我正在尝试将滑动窗口应用于数据框,类似于rollapply和SlidingWindow的工作方式。但是,我想知道这些功能或其他功能中的任何一个是否可以使用(1)为小数,而(2)可以小于采样率的步骤(请参见以下示例)。这样的功能可能会更有效地执行以下操作:
library(dplyr)
beaver1.1 <- beaver1 %>% mutate(activ = 0)
beaver1.2 <- beaver1 %>% mutate(activ = 1,
temp = temp + 1)
beaver_combined <- rbind(beaver1.1, beaver1.2)
beaver_combined <- beaver_combined %>%
mutate(time = time *.001)
window_freq <- .001
window_size <- .049
first_window <- min(beaver_combined$time)
last_window <- max(beaver_combined$time)
window_vector <- seq(first_window, last_window, window_freq)
windowing <- function(window_start){
window_end <- window_start + window_size
pullfrom <- beaver_combined %>%
filter(between(time, window_start, window_end)) %>%
group_by(activ) %>%
summarise(temp = mean(temp)) %>%
spread(activ, temp)
}
needsbinding <- mapply(windowing, window_vector)
do.call(rbind, needsbinding)
非常感谢!