我正在尝试使用combinations
包中的gtools
函数对值进行组合。
例如,我有向量cat_var
cat_var<-c("James","Ariana","Kevin","Bob")
然后,我想做
James Ariana
James Kevin
James Bob
Ariana Kevin
Ariana Bob
Kevin Bob
但是,当我使用combinations
函数时,组合是按字母顺序进行的,例如
> cat_var<-c("James","Ariana","Kevin","Bob")
> combinations(n = length(cat_var), r = 2, v = cat_var, repeats.allowed = FALSE)
[,1] [,2]
[1,] "Ariana" "Bob"
[2,] "Ariana" "James"
[3,] "Ariana" "Kevin"
[4,] "Bob" "James"
[5,] "Bob" "Kevin"
[6,] "James" "Kevin"
如何按照预定顺序进行组合?