Get the means of sub groups of means in R

With base, using aggregate

> aggregate(WLN~GROUP+WORD, mean, data=df)
  GROUP WORD      WLN
1     1    1 3.333333
2     1    2 2.333333
3     2    3 1.333333
4     2    4 1.000000

where df is @Metrics’ data.

Another alternative is using summaryBy from doBy package

> library(doBy)
> summaryBy(WLN~GROUP+WORD, FUN=mean, data=df)
  GROUP WORD WLN.mean
1     1    1 3.333333
2     1    2 2.333333
3     2    3 1.333333
4     2    4 1.000000

Leave a Comment