[R] Is there a function for finding local extrema.
Petr Pikal
petr.pikal at precheza.cz
Mon Jul 29 10:35:39 CEST 2002
On 26 Jul 2002 at 15:45, 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.
function (series, span = 3)
{
z <- embed(series, span)
s <- span%/%2
v <- max.col(z) == 1 + s
result <- c(rep(FALSE, s), v)
result <- result[1:(length(result) - s)]
result
}
This function based on prof.Ripley's suggestion some time ago
gives you logical vector identifying positions of peaks in time
series (similar result like peaks in S+). It identifies as a peak a
local maxima from n neighbour points where n is a span number.
>
>
> --
> _|_ \|/ \|/ Eryk Witold Wolski tel :0049-(0)30-8413-1543
> w w ´v´ 'v´ \'v'/ MPI Moleculare Genetik fax
> :0049-(0)30-8413-1139 | |
> /| |\/| |\ | | Mass Spectrometry Group http://www.molgen.mpg.de
> /.^.\
> m m m m m m mail :wolski at molen.mpg.de
> /|\
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.- 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._
Petr Pikal
petr.pikal at precheza.cz
p.pik at volny.cz
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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