按月

2014-11-05 30 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)