Skip to content
Prev 318072 / 398502 Next

remove rows in data frame by average

Many find the functions in the plyr package more convenient to use than the
do.call(rbind, lapply(split(...),...) business:

  > library(plyr)
  > ddply(dat1, .(Subject,Block),  summarize, MeanFeature1=mean(Feature1), MeanFeature2=mean(Feature2))
    Subject Block MeanFeature1 MeanFeature2
  1       1     1         55.0         29.0
  2       1     2         42.5         38.5
  3       1     3         64.0         14.0

Change the calls to 'mean' to calls to other summary functions like 'sum' or 'max' as you wish. 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com