为什么不使用paste0作为FUN的combn()给我预期的结果(r)

时间:2018-09-24 13:13:31

标签: r combn

我正在尝试使用combn()paste0作为函数来创建字符串组合列表,但是我得到的只是组合矩阵。我在做什么错了?

示例:

combn(LETTERS[1:5],3, FUN=paste0)

给我:

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "A"  "A"  "A"  "A"  "A"  "A"  "B"  "B"  "B"  "C"  
[2,] "B"  "B"  "B"  "C"  "C"  "D"  "C"  "C"  "D"  "D"  
[3,] "C"  "D"  "E"  "D"  "E"  "E"  "D"  "E"  "E"  "E"    

当我期望得到的东西是:

[1] "ABC" "ABD" "ABE" "ACD" "ACE" "ADE" ...

我想念什么?

1 个答案:

答案 0 :(得分:4)

您可以使用此命令,看看它是否有效吗?它对我有用。

combn(LETTERS[1:5],3, FUN=paste0, collapse = "")