How to select the row with the maximum value in each group

后端 未结 16 1988
北荒
北荒 2020-11-21 04:18

In a dataset with multiple observations for each subject I want to take a subset with only the maximum data value for each record. For example, with a following dataset:

16条回答
  •  一整个雨季
    2020-11-21 04:57

    do.call(rbind, lapply(split(group,as.factor(group$Subject)), function(x) {return(x[which.max(x$pt),])}))
    

    Using Base R

提交回复
热议问题