select maximum row value by group

前端 未结 5 1151
醉梦人生
醉梦人生 2021-01-20 07:53

I\'ve been trying to do this with my data by looking at other posts, but I keep getting an error. My data new looks like this:

id  year    name          


        
5条回答
  •  不要未来只要你来
    2021-01-20 07:59

    ave works here yet again, and will account for a circumstance with multiple rows for the maximum year.

    new[with(new, year == ave(year,id,FUN=max) ),]
    
    #  id year  name gdp
    #3  1 1982 Jamie  70
    #6  2 1992  Kate  67
    #9  3 1996   Joe  90
    

提交回复
热议问题