例如,我有一个向量c(1,2,3,4,5)
有不同的片段组合:
组合0:1 2 3 4 5
组合1:12345
组合2:1234 5
组合3:123 45
组合4:12 345
组合5:12345
组合6:12 34 5
组合7:12 3 45
组合8:1 23 45
组合9:15 23 4
组合10:14 23 5
…等等(有很多组合).
While the order does not matter: 14 23 5等于5 41 32(Hence, only one of these combinations is needed).
在R中有没有办法将一个向量分割成所有不同的可能片段组合?
我希望输出是一个(显然很长)嵌套列表,其中包含所有不同的可能片段组合.
对于组合9和10:
list(
list(c(1,5), c(2,3), 4),
list(c(1,4), c(2,3), 5)
)
[[1]]
[[1]][[1]]
[1] 1 5
[[1]][[2]]
[1] 2 3
[[1]][[3]]
[1] 4
[[2]]
[[2]][[1]]
[1] 1 4
[[2]][[2]]
[1] 2 3
[[2]][[3]]
[1] 5