Skip to content

Instantly share code, notes, and snippets.

@milosgajdos
Created November 20, 2015 21:05
Show Gist options
  • Save milosgajdos/5b42db7b4197e6b13777 to your computer and use it in GitHub Desktop.
Save milosgajdos/5b42db7b4197e6b13777 to your computer and use it in GitHub Desktop.
# split data per Species
species_frames <- split(iris,iris$Species)
# calculate mean per species
lapply(species_frames, function(x) colMeans(x[,"Sepal.Length"]))
# simple version of ^^ calculate mean over Sepal.Length split by Species
tapply(iris$Sepal.Length, iris$Species, mean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment