将timeAverage用于列

时间:2018-03-12 21:30:02

标签: package openair

我有一个问题,我想通过包 openair 的命令 timeAverage 获取每日积累的降水变量,所以我试试这个:

CovTemp <- read.table("CovPrec", header = TRUE, sep = ";", 
stringsAsFactors = FALSE, dec = ",", na.strings = "NA")

date <- ajuste_tiempos(CovPrec)
Met_CovPrec <- cbind(date, CovPrec[-c(3,4)])
Met_CovPrec$date <- as.POSIXct(strptime(Met_CovPrec$date,
                                              format = "%d/%m/%Y %H:%M", "GMT"))


Met_CovPrec_prom_day <- timeAverage(Met_CovPrec, avg.time = "day", statistic = "sum")

但结果适用于整个数据框,而不仅仅是数据列:

原始数据框 CovPrec

MS_NR SS_NR DATE HOUR VALUE 1 13095010 240 1/01/2014 0:00:00 NA 2 13095010 240 1/01/2014 0:10:00 NA 3 13095010 240 1/01/2014 0:20:00 NA 4 13095010 240 1/01/2014 0:30:00 NA 5 13095010 240 1/01/2014 0:40:00 NA 6 13095010 240 1/01/2014 0:50:00 NA

结果 Met_CovPrec_prom_day

日期MS_NR SS_NR VALUE                         1 2014-01-01 00:00:00 1885681440 34560 0 2 2014-01-02 00:00:00 1885681440 34560 0 3 2014-01-03 00:00:00 1885681440 34560 0 4 2014-01-04 00:00:00 1885681440 34560 28 5 2014-01-05 00:00:00 1885681440 34560 2 6 2014-01-06 00:00:00 1885681440 34560 0

感谢您的回答

1 个答案:

答案 0 :(得分:1)

“timeAverage”始终适用于整个数据框。您需要选择列,尝试使用:

Met_CovPrec_prom_day <- timeAverage(Met_CovPrec[, c("date", "VALUE")], avg.time = "day", statistic = "sum")