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

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.