how to get all possible combinations of the data table?

library(data.table)
DT <- data.table(x = 1:2, y = letters[1:2], z = letters[3:4])
i would like to create function to get data.table with all combination i pass in the function

getcom <- function(DT, ...)
getcom(DT, x, y) will get all combinations of x, y
getcom(DT, y, z) will get all combinations of y, z

try
expand.grid(DT$x, DT$y)

1 Like