【问题标题】:Get average value by month按月获取平均值
【发布时间】: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))

标签: r zoo


【解决方案1】:

...刚刚找到答案:来自hydroTSM 包:monthlyfunction(merged.precip.flow.and.T[,'E'], FUN=mean, na.rm=TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-04
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多