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

后端 未结 16 2032
北荒
北荒 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条回答
  •  旧时难觅i
    2020-11-21 04:54

    Another option is slice

    library(dplyr)
    group %>%
         group_by(Subject) %>%
         slice(which.max(pt))
    #    Subject    pt Event
    #      
    #1       1     5     2
    #2       2    17     2
    #3       3     5     2
    

提交回复
热议问题