我有一個data.frame,如下所示。在R data.frame中過濾重複的行
> df2 <- data.frame("StudentId" = c(1,1,1,2,2,3,3), "Subject" = c("Maths", "Maths", "English","Maths", "English", "Science", "Science"), "Score" = c(100,90,80,70, 60,20,10))
> df2
StudentId Subject Score
1 1 Maths 100
2 1 Maths 90
3 1 English 80
4 2 Maths 70
5 2 English 60
6 3 Science 20
7 3 Science 10
很少StudentIds,有重複列標題(值例如:ID 1具有2個條目「數學」我需要僅保持重複的行中的第一個 預期data.frame是。:
StudentId Subject Score
1 1 Maths 100
3 1 English 80
4 2 Maths 70
5 2 English 60
6 3 Science 20
我不能做到這一點。 任何想法。
另外[this](http://stackoverflow.com/questions/13967063/remove-duplicate-rows-in-r)和[this](http://stackoverflow.com/questions/13279582/select-only-the-first-rows-for-each-unique-value-of-column-in-r) –