Suppose I have the vector ["a","b","c"]
, then I'd like to create a list of vectors of all the unique combinations, of all sizes (order does not matter):
["a"]
["b"]
["c"]
["a","b"]
["a","c"]
["b","c"]
["a","b","c"]
How can I do this in R?
Suppose I have the vector ["a","b","c"]
, then I'd like to create a list of vectors of all the unique combinations, of all sizes (order does not matter):
["a"]
["b"]
["c"]
["a","b"]
["a","c"]
["b","c"]
["a","b","c"]
How can I do this in R?
We can try with combn
do.call("c", lapply(seq_along(v1), function(i) combn(v1, i, FUN = list)))
v1 <- letters[1:3]