从向量生成R中所有长度的所有组合 [英] Generate all combinations, of all lengths, in R, from a vector
本文介绍了从向量生成R中所有长度的所有组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有向量 [ a, b, c]
,那么我想创建所有<各种大小的strong>独特组合(顺序无关紧要):
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]
这篇关于从向量生成R中所有长度的所有组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文