不按字母顺序排列组合

时间:2019-10-02 07:54:15

标签: r combinations

我正在尝试使用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"

如何按照预定顺序进行组合?

0 个答案:

没有答案