R Aggregating Data It is relatively easy to collapse data in R using one or more BY variables and a defined function. http://www.statmethods.net/management/aggregate.html
# aggregate data frame mtcars by cyl and vs, returning means
# for numeric variables
attach(mtcars)
aggdata <-aggregate(mtcars, by=list(cyl,vs),
FUN=mean, na.rm=TRUE)
print(aggdata)
detach(mtcars)