【发布时间】:2019-03-25 17:28:57
【问题描述】:
我知道我可以在 dplyr:filter 中使用 POSIXct 作为参数。我已经通过使用 >= 等参数成功地缩短了我的数据。这是我的代码:
library (dplyr)
start <- as.POSIXct("2018-05-18 00:00")
tseq <- seq(from = start, length.out = 1440, by = "10 mins")
observations <- data.frame(
Time = tseq,
Temp = sample(10:37,1440, replace = TRUE, set.seed(seed = 10)),
Variable1 = sample(1:200,1440, replace = TRUE, set.seed(seed = 187)),
Variable2 = sample(300:800,1440, replace = TRUE, set.seed(seed = 333))
)
observations_short <- observations %>% filter (Time <= as.POSIXct ("2018-05-23 00:00", tz="CET") )
我认为这样的东西应该可以过滤每天 9:00 到 17:00h 的值,但我无法弄清楚它的工作语法。
observations_9to5 <- observations %>% filter (Time >= as.POSIXct ("09:00", tz="CET") ) %>% filter (Time <= as.POSIXct ("17:00", tz="CET") )
语法帮助,如果这通常适用于dplyr::filter,将不胜感激。如果这不适用于dplyr,是否有可能使用 xts 格式的数据?
【问题讨论】:
标签: r datetime dplyr time-series posixct