假设我有向量 [ a, b, c] ,那么我想创建所有独特组合(顺序无关紧要):
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"]如何在R中执行此操作?
How can I do this in R?
推荐答案我们可以尝试使用 combn
do.call("c", lapply(seq_along(v1), function(i) combn(v1, i, FUN = list)))数据
data
v1 <- letters[1:3]