我有以下的
另一方面,我有另一个包含以下信息的数据框df:
df
。dat <- data.frame(Cases = c("Student3","Student3","Student3","Student1","Student1",
"Student2","Student2","Student2","Student4"), Class = rep("Math", 9),
Scores = c(9,5,2,7,3,8,5,1,7), stringsAsFactors = F)
> dat
Cases Class Scores
1 Student3 Math 9
2 Student3 Math 5
3 Student3 Math 2
4 Student1 Math 7
5 Student1 Math 3
6 Student2 Math 8
7 Student2 Math 5
8 Student2 Math 1
9 Student4 Math 7
另一方面,我有另一个包含以下信息的数据框df:
d <- data.frame(Cases = c("Student3", "Student1",
"Student2", "Student4"), Class = rep("Math", 4), stringsAsFactors = F)
Cases Class
1 Student3 Math
2 Student1 Math
3 Student2 Math
4 Student4 Math
我想提取每个学生
的最高分数
。因此,我的输出应该是这样的:
> dat_output
Cases Class Scores
1 Student3 Math 9
2 Student1 Math 7
3 Student2 Math 8
4 Student4 Math 7
我试过使用merge
,但它并没有仅提取最高的scores
。