[R] Is there a function for finding local extrema.

Robert H Creecy Robert.H.Creecy at census.gov
Fri Jul 26 16:34:01 CEST 2002


Assuming the first and last values in the vector y can't be determined 
to be local maxima, try

 max<-1+which(( y[2:(n-1)] > y[1:(n-2)]) & (y[2:(n-1)] > y [3:n]))

max is now a vector of indicies of the local maxima, and y[max] are 
their values



Witold Eryk Wolski wrote:

> I have a vector with about 100.000 values representing a quite regular 
> function (sinusoid like).
> I would like to find all local maxima of this function (should be 
> about 4000). Is there a native routine for R?
> Thanks in advance
> Eryk.
>


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list