0
votes

I’ve used zoo aggregate function to get the monthly average from daily data using:

monthlyMeanTemp <- aggregate(merged.precip.flow.and.T[,'E'], as.yearmon, mean, na.rm = TRUE) # ‘E’ is the column of temperature

Here is the head and tail of the result:

Jan 1979     Feb 1979     Mar 1979     Apr 1979     May 1979     Jun 1979 
-14.05354839 -11.83078929  -7.32150645  -0.03214333   6.16986774  14.00944000

Apr 1997  May 1997  Jun 1997  Jul 1997  Aug 1997  Sep 1997 
1.438547  7.421910 12.764450 15.086206 17.376026 10.125013`

Is it possible to get the mean by month (i.e., the mean of all the January values, mean of all the February values etc.) without resorting to padding missing months with NA, forming a n x 12 matrix (where n is the number of years), and then using the colMeans function?

1
In your aggregate statement replace as.yearmon with function(x) cycle(as.yearmon(x))G. Grothendieck

1 Answers

1
votes

...just found the answer: From the hydroTSM package: monthlyfunction(merged.precip.flow.and.T[,'E'], FUN=mean, na.rm=TRUE)