【发布时间】:2021-11-08 07:35:38
【问题描述】:
我在一个大型(6 个月)数据帧中有一个 date_time POSIXct 对象,增量为 5 秒,我想将其聚合成 30 秒的“块”。 6x 5s 是 30s 所以 nrow(df)/6 给出了正确的序列长度。
我尝试了以下方法:
Date_time_30s <- aggregate(Mn$Date_time, list(seq(0, length.out = nrow(Mn)) %/% 6), FUN = mean)
前 6 个 date_times 如下所示:
"","Date_time","Depth","Temperature","Light_Level","Date"
"1",2013-10-14 12:30:00,
"2",2013-10-14 12:30:05,
"3",2013-10-14 12:30:10,
"4",2013-10-14 12:30:15,
"5",2013-10-14 12:30:20,
"6",2013-10-14 12:30:25,
所以平均值应该是 2013-10-14 12:30:12.5,但结果是 2013-10-14 11:30:12。 没有小数秒(options(digits.secs=3) 解决了一个简单的格式问题)但是小时是错误的。
怎么了?
输入(头部(Mn))
structure(list(Date_time = structure(c(1381721400, 1381721405,
1381721410, 1381721415, 1381721420, 1381721425), class = c("POSIXct",
"POSIXt"), tzone = "Asia/Tokyo"), Depth = c(64.4476273148148,
65.9476334145628, 65.9476395143109, 66.4476456140589, 67.9476517138069,
66.9476578135549), Temperature = c(27.549999, 27.5, 27.400002,
27.35, 27.25, 27.200001), Light_Level = c(148L, 148L, 148L, 148L,
147L, 147L), Date = structure(c(15992, 15992, 15992, 15992, 15992,
15992), class = "Date"), vv = c(0, 0.300001, 1e-06, 0.100001,
0.300001, -0.199999), vv_abs = c(0, 0.300001, 1e-06, 0.100001,
0.300001, 0.199999)), row.names = c(NA, 6L), class = "data.frame")
【问题讨论】: