【发布时间】:2020-11-05 18:58:12
【问题描述】:
我正在尝试使用函数dm2seasonal 在 R 中按季节计算累积降水量。
例如,这是我的动物园每日降水站列表中第一个元素的str:
(例如,由于字符限制,我没有包括 dput(listDF_zoo[[1]]))
> str(listDF_zoo[[1]])
‘zoo’ series from 1915-11-01 to 1945-11-01
Data: num [1:9382] 0 0 0 0 0 18.5 9.4 0 0 10.4 ...
Index: Date[1:9382], format: "1915-11-01" "1915-11-02" "1915-11-03" "1915-11-04" "1915-11-05" "1915-11-06" "1915-11-07" ...
我正在使用以下代码:
#Cumulative precipitation in spring (March 1 to May 31)
SpringCumMean <- lapply(listDF_zoo,function(x){dm2seasonal(x, season ="MAM", FUN=sum)})
但我收到以下错误:
> SpringCumMean <- lapply(listDF_zoo,function(x){dm2seasonal(x, season ="MAM", FUN=sum)})
Show Traceback
Rerun with Debug
Error in aggregate.data.frame(as.data.frame(x), ...) :
no rows to aggregate In addition: Warning message:
In extract.zoo(x = x, trgt = season) :
There were no elements of 'x' within 'trgt'
我不明白为什么说元素没有行...
有什么办法吗?
【问题讨论】:
-
请显示一个有效的
dm2seasonal的非重复调用。方法似乎依赖于aggregate,由于缺少观察结果,它可以返回no rows to aggregate。 -
我知道我在列表的第 46 元素中遇到了错误。是否可以跳过循环中的错误以避免停止循环?