I have a vector like this:
x <- c(0, 0, 0, 0, 4, 5, 0, 0, 3, 2, 7, 0, 0, 0)
I want to keep only the elements from position 5 to 11. I w
This would also work :
x[cumsum(x) & rev(cumsum(rev(x)))] # [1] 4 5 0 0 3 2 7