I have the following code:
main_cols <- c('num', 'let')
dt <- data.table(num = 1:5, let = letters[1:5])
dt
new_dt <- dt[CJ(num = num
, let = let
, unique = TRUE)
, on = main_cols
]
head(new_dt, 10)
The thing is: I want to pass the columns to cross-join on as a vector. How do I “unpack” main_cols
inside the CJ
function? Thanks.