将一个元素与不同列的所有其他元素组合/ R

combine one element with all other elements of a different column / R

我确实在每个组 (a1 - a8) 中有两对球员,我想将一场比赛的元素与第二场比赛的元素结合起来,以获得每个人与另一场比赛的所有组合。

#groups a1-a8 with two matchups

$a1
     [,1]     [,2]    
[1,] "Paul"   "Stefan"
[2,] "Markus" "Andre" 

$a2
     [,1]     [,2]   
[1,] "Julian" "Lupo" 
[2,] "Jo"     "Peter"
... 

所以我需要这样的东西..

matchups for a1

$Paul
              [,1]     [,2]    
        [1,] "Paul"   "Paul"
        [2,] "Stefan" "Andre" 

$Markus
             [,1]     [,2]    
        [1,] "Markus" "Markus"
        [2,] "Stefan" "Andre" 

$Stefan  
             [,1]     [,2]    
        [1,] "Stefan" "Stefan"
        [2,] "Paul"   "Markus" 

$Andre
             [,1]     [,2]    
        [1,] "Andre"  "Andre"
        [2,] "Paul"   "Markus" 

每个组(a2 -> a8)都应该相同

有人知道如何解决我目前无法解决的问题。非常感谢

下面的代码应该可以解决问题(如果你想要其他对局,只需替换所有地方的 a1): split(expand.grid(a=a1[,1], b=a1[,2]), a1[,1])