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:
by is a version of tapply for data frames:
by
tapply
res <- by(group, group$Subject, FUN=function(df) df[which.max(df$pt),])
It returns an object of class by so we convert it to data frame:
do.call(rbind, b) Subject pt Event 1 1 5 2 2 2 17 2 3 3 5 2