>Given a series of observations, I want to know how many consecutive past >observations are below the last one. prune=function(m) { mr=rev(m) ms=cumsum(mr < mr[1]) sum(seq_along(ms) - ms == 1) - 1 } prune(c(3, 4, 10, 14, 8, 3, 4, 8, 9)) # 4 prune(c(3, 4, 10, 14, 8, 3, 4, 11, 9)) # 0 Heikki Kaskelma