【问题标题】:R combinating vector [duplicate]R组合向量[重复]
【发布时间】:2015-10-21 00:01:10
【问题描述】:

假设我有向量

c("A","B","C")

我需要获取列表或向量组合所有变量(顺序不重要)

"A,B"
"A,C"
"B,C"
"A,B,C"

【问题讨论】:

  • 可能类似于unlist(sapply(2:length(x), function(i) combn(x, i, toString)))
  • 怎么样 expand.grid(c("A","B","C"), c("A","B","C"))

标签: r


【解决方案1】:

你可以这样做:

require(gtools)
all.perm <- sapply(1:length(letters),function(len){ 
  permutations(n = length(letters), r = len, v = letters)
})

【讨论】:

    猜你喜欢
    • 2019-02-23
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多