我有一個數據幀,每小時觀測和模擬空氣質量數據。附加信息被測量站,國家,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