similar to data.table::CJ and base::expand.grid except for rows of data.tables.
CJ.dt(..., groups = NULL)
data.tables
a character vector corresponding to column names of grouping vars in all of the data.tables
CJ.dt computes successive cartesian join over rows of each table paying no attention to whatever the tables are keyed on.
# NOT RUN {
#' CJ.dt(data.table(c(1,2,2),c(1,1,1)),data.table(c("a","b"),c("c","d")))
#If you want to expand x to unique values of a non-unique columns in y
x <- data.table(c(1,2,3),c("a","b","b"))
y <- data.table(id=c(1,2,2,1,3),value=c(2,4,1,7,3))
z <- CJ.dt(x, y[,list(id=unique(id))])
#if you want to merge this back to y
y[z,on="id",allow.cartesian=TRUE] #or z[y,on="id",allow.cartesian=TRUE]
# }
Run the code above in your browser using DataLab