I have a dataframe like this:
block plot date data
1 1 aug 11.95171507
1 1 aug 18.41451063
1 2 aug 9.506155236
1 2 aug 13.26259947
1 3 aug 17.53616835
1 3 sep 15.40950767
2 1 sep 23.03616678
2 1 sep 17.07067258
2 2 sep 11.58278798
2 2 sep 13.15443304
I would like to calculate the means of data across plot based on block and date. Eventually, i would like to have 5 means. Thanks for your help.
Probably the path of least resistance is to use plyr
:
library(plyr)
ddply(yourData, c("block", "date"), summarize, outVal = mean(data))
You can do similar things with data.table
, aggregate
, by
and probably a whole host of other functions. Take a few minutes to peruse the R tag here on SO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With