Re: [R] Need some vectorizing help

2011-11-26 Thread Scott Tetrick
Thank you very much David - R is so rich, the easy way can be hard to find. Just to close this out for others, the final solution I used was: Peak2Return <- function(v) { S <- cummax(v) L <- which((v ==S) & (diff(c(0,v)<0)) R <- sapply(v[L], function(x,S) {which(x < S)[1]; }, S) now you h

Re: [R] Need some vectorizing help

2011-11-24 Thread David Winsemius
On Nov 24, 2011, at 4:52 AM, Scott Tetrick wrote: So I have a problem that I'm trying to get through, and I just can't seem to get it to run very fast in R. What I'm trying to do is to find in a vector a local peak, then the next time that value is crossed later. I don't care about peaks

[R] Need some vectorizing help

2011-11-24 Thread Scott Tetrick
So I have a problem that I'm trying to get through, and I just can't seem to get it to run very fast in R. What I'm trying to do is to find in a vector a local peak, then the next time that value is crossed later. I don't care about peaks that may be lower than this first one - they can be ig