我正在浏览 R 中的一些示例代码,这些代码获取动物园对象(时间序列)中每秒的最后数据。我让代码正常工作,但我不明白以下行:
time(tmp) <- as.integer(time(tmp) + 1e-7) + Epoch
为什么我们要在时间值上加上 1e-7?在此处粘贴完整代码。请帮助
library(zoo)
zsec <- structure(1:10, index = structure(c(1234760403.968, 1234760403.969,
1234760403.969, 1234760405.029, 1234760405.029, 1234760405.03,
1234760405.03, 1234760405.072, 1234760405.073, 1234760405.073
), class = c("POSIXt", "POSIXct"), tzone = ""), class = "zoo")
# tmp is zsec with time discretized into one second bins
tmp <- zsec
st <- start(tmp)
Epoch <- st - as.numeric(st)
time(tmp) <- as.integer(time(tmp) + 1e-7) + Epoch
# find index of last value in each one second interval
ix <- !duplicated(time(tmp), fromLast = TRUE)