I have the following vector
v = c(F, F, F, T, F, F, F, F, F, T, F, F, F)
How can I change v so that the previous 2 elements and the following
Yet another approach. Create a set of lagged vectors, and or them together:
or
library(Hmisc) library(functional) within.distance <- function(x, d=2) { FLag <- function(x, shift) { x <- Lag(x, shift) x[is.na(x)] <- FALSE return(x) } l <- lapply((-d):d, Curry(FLag, x=x)) return(Reduce(`|`, l)) }