Skip to content

Instantly share code, notes, and snippets.

@andilabs
Created August 30, 2013 11:47
Show Gist options
  • Save andilabs/6389071 to your computer and use it in GitHub Desktop.
Save andilabs/6389071 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment