>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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.