Collapse data frame by group using different functions on each variable
问题 Define df<-read.table(textConnection('egg 1 20 a egg 2 30 a jap 3 50 b jap 1 60 b')) s.t. > df V1 V2 V3 V4 1 egg 1 20 a 2 egg 2 30 a 3 jap 3 50 b 4 jap 1 60 b My data has no factors so I convert factors to characters: > df$V1 <- as.character(df$V1) > df$V4 <- as.character(df$V4) I would like to "collapse" the data frame by V1 keeping: The max of V2 The mean of V3 The mode of V4 (this value does not actually change within V1 groups, so first, last, etc might do also.) Please note this is a