删除包含R中各列重复值组合的行

时间:2019-07-09 15:03:59

标签: r duplicates subset

我有以下数据框:

     Player_1     Player_2    Player_3    Player_4        Player_5    Player_6      Player_7       total_sal
1   Mike Reilly Andrew Harris   RB 1    Dominque Rhymes Duron Carter    BC D    Shaquille Johnson   39084
2   Mike Reilly Andrew Harris   RB 1    Dominque Rhymes Shaquille Johnson   BC D    Duron Carter    39084
3   Mike Reilly Andrew Harris   RB 1    Duron Carter    Shaquille Johnson   BC D    Dominque Rhymes 39084
4   Mike Reilly Andrew Harris   RB 2    Dominque Rhymes Duron Carter    BC D    Shaquille Johnson   39084
5   Mike Reilly Andrew Harris   RB 2    Dominque Rhymes Shaquille Johnson   BC D    Duron Carter    39084
6   Mike Reilly Andrew Harris   RB 2    Duron Carter    Shaquille Johnson   BC D    Dominque Rhymes 39084

我关心的是Player_1至Player_7列。我想删除数据框中的行,这些行中出现了相同的播放器组合。例如,在上面的第1行至第3行中,第4行至第6行在不同的列中显示了相同的玩家组合。我想知道是否存在一种方法可以检测并删除这些重复的行,因此在上面的示例中,最终的数据帧将只出现1-3行,而出现4-6行(与哪一行无关)。

使用的数据:

structure(list(X = c(29L, 32L, 34L, 44L, 47L, 49L), Player_1 = c("Mike Reilly", 
"Mike Reilly", "Mike Reilly", "Mike Reilly", "Mike Reilly", "Mike Reilly"
), Player_2 = c("Andrew Harris", "Andrew Harris", "Andrew Harris", 
"Andrew Harris", "Andrew Harris", "Andrew Harris"), Player_3 = c("RB 1", 
"RB 1", "RB 1", "RB 2", "RB 2", "RB 2"), Player_4 = c("Dominque Rhymes", 
"Dominque Rhymes", "Duron Carter", "Dominque Rhymes", "Dominque Rhymes", 
"Duron Carter"), Player_5 = c("Duron Carter", "Shaquille Johnson", 
"Shaquille Johnson", "Duron Carter", "Shaquille Johnson", "Shaquille Johnson"
), Player_6 = c("BC D", "BC D", "BC D", "BC D", "BC D", "BC D"
), Player_7 = c("Shaquille Johnson", "Duron Carter", "Dominque Rhymes", 
"Shaquille Johnson", "Duron Carter", "Dominque Rhymes"), total_sal = c(39084L, 
39084L, 39084L, 39084L, 39084L, 39084L)), row.names = c(NA, 6L
), class = "data.frame")

0 个答案:

没有答案