The plyr
package can be used for this. With the ddply()
function you can split a data frame on one or more columns and apply a function and return a data frame, then with the summarize()
function you can use the columns of the splitted data frame as variables to make the new data frame/;
dat <- read.table(textConnection('Group Score Info
1 1 1 a
2 1 2 b
3 1 3 c
4 2 4 d
5 2 3 e
6 2 1 f'))
library("plyr")
ddply(dat,.(Group),summarize,
Max = max(Score),
Info = Info[which.max(Score)])
Group Max Info
1 1 3 c
2 2 4 d