我有一个数据帧,每小时观测和模拟空气质量数据。附加信息被测量站,国家,stationtype和型号:R:聚合与时间平均值
> head(PM10val)
date station type model country obs mod
1 2009-01-01 00:00:00 BELAB01 sB chimere BE 63 13.45
2 2009-01-01 01:00:00 BELAB01 sB chimere BE 50 18.71
3 2009-01-01 02:00:00 BELAB01 sB chimere BE 77 20.65
4 2009-01-01 03:00:00 BELAB01 sB chimere BE 68 21.42
5 2009-01-01 04:00:00 BELAB01 sB chimere BE 58 22.47
6 2009-01-01 05:00:00 BELAB01 sB chimere BE 62 24.02
我想使用timeAverage函数(计算包含日期字段中数据帧的时间平均)的OpenAir包的每日计算或年度平均值,每站和每个模型。我想:
> anmean <- aggregate(PM10val, by=list(PM10val$station,PM10val$model),
+ function (x) timeAverage(x,avg.time="year",data.thresh=75, statistic="mean"))
这应该算年平均为平均“OBS”和每个型号和台“国防部”,有75%的数据捕获阈值。 但它返回:
Error in `[.default`(mydata, , Names) : incorrect number of dimensions
11 NextMethod("[")
10 `[.POSIXct`(mydata, , Names)
9 mydata[, Names]
8 checkPrep(mydata, vars, type = "default", remove.calm = FALSE,
strip.white = FALSE)
7 timeAverage(x, avg.time = "year", data.thresh = 75, statistic = "mean")
6 FUN(X[[1L]], ...)
5 lapply(X = split(e, grp), FUN = FUN, ...)
4 FUN(X[[1L]], ...)
3 lapply(x, function(e) {
ans <- lapply(X = split(e, grp), FUN = FUN, ...)
if (simplify && length(len <- unique(sapply(ans, length))) ==
1L) { ...
2 aggregate.data.frame(PM10val, by = list(PM10val$station, PM10val$model),
function(x) timeAverage(x, avg.time = "year", data.thresh = 75,
statistic = "mean"))
1 aggregate(PM10val, by = list(PM10val$station, PM10val$model),
function(x) timeAverage(x, avg.time = "year", data.thresh = 75,
statistic = "mean"))
我在做什么错了?我总是可以使用一个循环,但我不认为这是要走的路。 谢谢!
究竟是什么'timeAverage(PM10val,avg.time =“year”,data.thresh = 75,statistic =“mean”)'return?另外,出错后请提供'traceback()'的结果。 – 2015-02-23 12:04:31
我在上面的主要问题中添加了它。对不起,这是我第一次问一个问题! – 2015-02-23 15:13:49