-2

This may be quite simple but my knowledge of R is somewhat lacking so I would really appreciate some help. Here goes: I have 6 columns (Site, Year, Plot, Lawn, Tussock, Grass). My rows are as follows: I have 2 sites (high and low). For every site, I have 3 years (2013, 2014 and 2015). For every year, I have 5 plots (1,2,3,4,5). I then have the average height for Lawn, Tussock and Grass for each of those rows, e.g.:

Site     Year   Plot    Lawn    Tussock Grass
High      2013   1      5.43    36.98   10.16
High      2013   2      2.66    66.18   5.95
High      2013   3      2.73    44.08   6.59
High      2013   4      2.75    45.42   6.55
High      2013   5      4.44    33.26   7.97
High      2014   1      8.32    34.47   11.62
High      2014   2      6.22    28.78   8.41
High      2014   3      8.74    43.39   16.26
High      2014   4      4.19    30.88   8.96
High      2014   5      5.74    22.42   7.68

How do I go about getting an average value for Lawn, Tussock and Grass for each year for each site? Any advice would be greatly appreciated.

Sumedh
  • 4,345
  • 1
  • 15
  • 31
Dominique
  • 97
  • 1
  • 9
  • for a data.frame named df, use `aggregate(. ~ Site + Year + Plot, data=df, FUN=mean)` – lmo Jun 29 '16 at 18:30

2 Answers2

2

Assuming df is your dataframe

library(dplyr)
df %>% group_by(Site, Year) %>% summarise_each(funs(mean), -Plot)
Pierre L
  • 26,748
  • 5
  • 39
  • 59
Sumedh
  • 4,345
  • 1
  • 15
  • 31
0

Replace tb with whatever your data frame is called.

aggregate(cbind(Lawn,Tussock,Grass) ~ Site + Year, data=tb, mean)
Jacob F
  • 346
  • 1
  • 6