-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
Description
There is not straight way to do cross join currently. User need to add a column with a constant value in both datasets and join on that column. This could be nicely addressed in a similar way as it is in SQL where you can use SELECT ... FROM t1 JOIN t2 ON 1=1, where 1=1 is used to evaluate to TRUE for every row.
Eventually allow.cartesian could be set to TRUE when on=TRUE detected so the use case would look like:
X[Y, on=TRUE]And corresponding SQLite
library(RSQLite)
library(data.table)
X=data.table(a=1:2)
Y=data.table(b=letters[1:2])
conn=dbConnect(SQLite())
dbWriteTable(conn, "t1", X)
dbWriteTable(conn, "t2", Y)
dbGetQuery(conn, "SELECT * FROM t1 JOIN t2 ON 1=1;")
# a b
#1 1 a
#2 1 b
#3 2 a
#4 2 bUpdate https://stackoverflow.com/questions/25888706/r-data-table-cross-join-not-working when solved.
UweBlock, MichaelChirico, rowrowrowyourboat, d-sci, jan-glx and 5 more