如何在R中的字符串向量中创建元素的无序组合列表?

元素的无序组合意味着值的组合没有任何特定的安排。例如,如果我们具有三个值1、2和3,那么它们可以按以下无序排列方式进行排列-

"one"
"two" "three"
"one" "two"
"one" three"
"two" "three"
"one" "two" "three"

示例

x<-c("India","China","Russia","Canada") unlist(lapply(seq_along(x),combn,x=x,simplify=FALSE),recursive=FALSE)

输出结果

[[1]]
[1] "India"
[[2]]
[1] "China"
[[3]]
[1] "Russia"
[[4]]
[1] "Canada"
[[5]]
[1] "India" "China"
[[6]]
[1] "India" "Russia"
[[7]]
[1] "India" "Canada"
[[8]]
[1] "China" "Russia"
[[9]]
[1] "China" "Canada"
[[10]]
[1] "Russia" "Canada"
[[11]]
[1] "India" "China" "Russia"
[[12]]
[1] "India" "China" "Canada"
[[13]]
[1] "India" "Russia" "Canada"
[[14]]
[1] "China" "Russia" "Canada"
[[15]]
[1] "India" "China" "Russia" "Canada"

示例

y<-c("Winter","Rainy","Summer") unlist(lapply(seq_along(y),combn,x=y,simplify=FALSE),recursive=FALSE)

输出结果

[[1]]
[1] "Winter"
[[2]]
[1] "Rainy"
[[3]]
[1] "Summer"
[[4]]
[1] "Winter" "Rainy"
[[5]]
[1] "Winter" "Summer"
[[6]]
[1] "Rainy" "Summer"
[[7]]
[1] "Winter" "Rainy" "Summer"