为什么openair timeAverage 会从数据框中删除某些列?
例如我有这个数据框:
> dput(Df)
structure(list(key_date = c("2017-04-30", "2017-05-01", "2017-05-01",
"2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01",
"2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01",
"2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01",
"2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01", "2017-05-01",
"2017-05-01"), date = structure(c(1493593200, 1493596800, 1493600400,
1493604000, 1493607600, 1493611200, 1493614800, 1493618400, 1493622000,
1493625600, 1493629200, 1493632800, 1493636400, 1493640000, 1493643600,
1493647200, 1493650800, 1493654400, 1493658000, 1493661600, 1493665200,
1493668800, 1493672400, 1493676000), class = c("POSIXct", "POSIXt"
), tzone = ""), PM = c(5.1, 4.8, 4.4, 7.4, 6.9, 9.3, 7.3, 10.3,
6.4, 4, 8.2, 5.6, 6.7, 4.4, 8.1, 6.1, 3.4, NA, 10.2, 11.3, 7.3,
8.6, 6, 10.5), site = c("LW2", "LW2", "LW2", "LW2", "LW2", "LW2",
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2",
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2"
), code = c("LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2",
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2",
"LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2", "LW2"), airport = structure(c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_), .Label = character(0), class = "factor"),
ws = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), wd = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), tempi = c(NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_), humidity = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c("key_date",
"date", "PM", "site", "code", "airport", "ws", "wd", "tempi",
"humidity"), row.names = c(NA, -24L), class = "data.frame")
申请时间平均:
Df <- timeAverage(Df, avg.time = "1 hour")
Warning message:
In checkPrep(mydata, vars, type = "default", remove.calm = FALSE, :
Detected data with Daylight Saving Time, converting to UTC/GMT
>
> dput(Df)
structure(list(date = structure(c(1493596800, 1493600400, 1493604000,
1493607600, 1493611200, 1493614800, 1493618400, 1493622000, 1493625600,
1493629200, 1493632800, 1493636400, 1493640000, 1493643600, 1493647200,
1493650800, 1493654400, 1493658000, 1493661600, 1493665200, 1493668800,
1493672400, 1493676000, 1493679600), class = c("POSIXct", "POSIXt"
), tzone = "GMT"), PM = c(5.1, 4.8, 4.4, 7.4, 6.9, 9.3, 7.3,
10.3, 6.4, 4, 8.2, 5.6, 6.7, 4.4, 8.1, 6.1, 3.4, NaN, 10.2, 11.3,
7.3, 8.6, 6, 10.5), ws = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN), wd = c(NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN), tempi = c(NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN), humidity = c(NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
NaN, NaN, NaN, NaN, NaN, NaN)), .Names = c("date", "PM", "ws",
"wd", "tempi", "humidity"), row.names = c(NA, -24L), class = c("tbl_df",
"tbl", "data.frame"))
列:key_date、code、site 被删除。为什么?我怎样才能保留它们?
此外,它将我的数据更改为NA
-NaN
我如何保留NA
数据?
编辑:
我设法保留了这些列:
Df <- timeAverage(Df, avg.time = "1 hour", type = c("site", "code"))
但是我怎样才能保持这些NA
价值观呢?