我想根据可变时间间隔过滤我的时间序列。更具体地说,考虑来自时间戳t的时间t_i。我想过滤我的时间序列,以便剩下的时间序列只包含从t_i - 15 分钟到并包括t_i + 15 分钟的时间戳。
这是我尝试过的:
library(lubridate)
library(dplyr)
mv <- 2 # moving window
t <- as.POSIXct("2020-06-20 12:00", tz="UTC") # time stamp
time <- seq(ymd_hm('2020-01-01 00:00'),ymd_hm('2020-12-31 23:45'), by = '15 mins')
ts <- tibble(time=time, data=sin(seq(1,length(time),1)))
# What I did:
ts %>%
filter(time >= t - mv*24*60*60) %>%
filter(time <= t) %>%
filter(strftime(time, format = "%H:%M", tz = "UTC") >= strftime(t-15*60, format = "%H:%M", tz = "UTC")) %>%
filter(strftime(time, format = "%H:%M", tz …Run Code Online (Sandbox Code Playgroud)