select maximum row value by group

前端 未结 5 2139
渐次进展
渐次进展 2021-01-20 07:45

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 08:00

    Your ddply effort looks good to me, but you referenced the original dataset in the callback function.

    ddply(new,~id,function(x){x[which.max(new$year),]})
    # should be
    ddply(new,.(id),function(x){x[which.max(x$year),]})
    

提交回复
热议问题