假设我有向量["a","b","c"]
,那么我想创建所有唯一组合的向量列表,所有大小(顺序无关紧要):
["a"]
["b"]
["c"]
["a","b"]
["a","c"]
["b","c"]
["a","b","c"]
我怎样才能在R?
中这样做答案 0 :(得分:3)
我们可以尝试combn
do.call("c", lapply(seq_along(v1), function(i) combn(v1, i, FUN = list)))
v1 <- letters[1:3]