Skip to content

Instantly share code, notes, and snippets.

@johncolby
Created June 22, 2011 17:23
Show Gist options
  • Save johncolby/1040603 to your computer and use it in GitHub Desktop.
Save johncolby/1040603 to your computer and use it in GitHub Desktop.
An example showing how to obtain the mean for each subject across multiple observations in a data frame
library(plyr)
data = arrange(data.frame(ID=1:10, FA=runif(50, 0.2, 0.8)), ID)
ddply(data, 'ID', mean) # using plyr library
aggregate(data, list(ID=data$ID), mean) # using base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment