【发布时间】:2014-11-05 12:40:41
【问题描述】:
我使用 zoo 聚合函数从每日数据中获取月平均值:
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 x 12 矩阵(其中 n 是年数),然后使用 colMeans 函数?
【问题讨论】:
-
在您的汇总语句中,将
as.yearmon替换为function(x) cycle(as.yearmon(x))