问题
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?
回答1:
We can try with combn
do.call("c", lapply(seq_along(v1), function(i) combn(v1, i, FUN = list)))
data
v1 <- letters[1:3]
来源:https://stackoverflow.com/questions/40049313/generate-all-combinations-of-all-lengths-in-r-from-a-vector