Skip to content

Instantly share code, notes, and snippets.

@hamiltont
Last active August 29, 2015 14:02
Show Gist options
  • Save hamiltont/2d0c2f946672fac6cb55 to your computer and use it in GitHub Desktop.
Save hamiltont/2d0c2f946672fac6cb55 to your computer and use it in GitHub Desktop.
> # Setup data
> names <- c("Field 1","Field 2","Field 3")
> area <- c(1.3,1.4,1.1)
> soil <- factor(c("wet","dry","wet"))
> worms <- data.frame(names,area,soil)
> worms
names area soil
1 Field 1 1.3 wet
2 Field 2 1.4 dry
3 Field 3 1.1 wet
> # Group area vector by soil type vector
> # and find the mean of each group
> by(worms$area,worms$soil,mean)
soil: dry
[1] 1.4
soil: wet
[1] 1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment