按月

2014-11-05 33 views
0

我用动物园聚合函数使用摆脱日常数据的月平均获取平均值:按月

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

下面是结果的头和尾:

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` 

是否可以按月计算平均值(即所有1月值的均值,所有2月值的平均值等),而不使用填充NA的缺失月份,形成n×12矩阵(其中n是年数),然后使用colMeans函数?

+0

在您的累计语句来替换'as.yearmon'用'函数(x)的循环(as.yearmon(X))' – 2014-11-05 15:05:02

回答

1

...只是找到了答案:从hydroTSM包:monthlyfunction(merged.precip.flow.and.T[,'E'], FUN=mean, na.rm=TRUE)