我正在尝试使用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" ...
我想念什么?
答案 0 :(得分:4)
您可以使用此命令,看看它是否有效吗?它对我有用。
combn(LETTERS[1:5],3, FUN=paste0, collapse = "")