I\'ve got a first vector, let\'s say x that consists only of 1\'s and -1\'s. Then, I have a second vector y that consists of 1\'s, -1\'s, and zeros. Now, I\'d like to create a v
You could use apply like this, although it is essentially a pretty way to do a loop, I'm not sure if it will be faster (it may or may not).
apply
y1 <- unlist(lapply(1:length(x), function(i){1 %in% y[max(0, (i-n)):i]})) z <- as.numeric(x==1) * as.numeric(y1)