powered by
keeponly(x, extremes = c(0, 100), nconsec = 2)
x
nconsec
vec <- c(0, 0, 0, 4, 4, 4, 100, 100, 100, 100) vec[keeponly(vec)] # the original vector need not be ordered vec <- c(100, 4, 100, 4, 0, 100, 0, 4, 0, 100) keeponly(vec)
Run the code above in your browser using DataLab