How to get the maximum value by group

前端 未结 5 1091
太阳男子
太阳男子 2020-11-27 07:00

I have a data.frame with two columns: year and score. The years go from 2000-2012 and each year can be listed multiple times. In the s

5条回答
  •  死守一世寂寞
    2020-11-27 07:37

    If you know sql this is easier to understand

    library(sqldf)
    sqldf('select year, max(score) from mydata group by year')
    

    Update (2016-01): Now you can also use dplyr

    library(dplyr)
    mydata %>% group_by(year) %>% summarise(max = max(score))
    

提交回复
热议问题