0

I'm pretty new to R having only gone through the basics at uni so far so I'm sorry if this is a really simple question that's been answered before.

Basically this is how my data looks right now. I've subsetted the Plants, Treatments and Soils. What I need to do is figure out how to calculate the mean of the ShootFresh and RootFresh of each plant for the control and competition treatments for each of the soil types. My efforts so far just calculate the mean of each plant ShootFresh and RootFresh in the control and competition but combine the soils.... I can't seem to figure out how to use all three factors.

Image of data

This is the code I'm using at the moment

tapply(F.ovina$ShootFresh,F.ovina$Treatment,FUN=mean)

Again I'm really sorry if this has been asked but I couldn't make heads or tails of any other answers!

Thomas
  • 43,637
  • 12
  • 109
  • 140
  • 2
    Try `with(F.ovina, tapply(ShootFresh, list(Treatment, Plant, Soil), FUN=mean, na.rm=TRUE))` or any of the `aggregate/dplyr/data.table` options by specifying 3 variables as the grouping variable. If you are using `dplyr`, `F.ovina %>% group_by(Treatment, Plant, Soil) %>% summarise_each(funs(mean))` gets both the `ShootFresh` and `RootFresh` mean for those group combinations. – akrun Mar 12 '15 at 17:49
  • Thanks you akrun that seemed to work perfectly! @akrun I have a lot to learn when it comes to R – Amy Reddick Mar 12 '15 at 17:54
  • 1
    A screenshot of data isn't very helpful. [Take a look at this](http://stackoverflow.com/q/5963269/903061) for advice on how to ask your next question. – Gregor Thomas Mar 12 '15 at 17:55
  • 1
    @AmyReddick feel free to answer your own question with an example using your data – rawr Mar 12 '15 at 17:57

0 Answers0