peaks | R Documentation |
Find the local maxima in a vector.
peaks(x, span = 3, ties = "first", ends = TRUE)
x |
any numeric vector. Missing values are permitted, but suppress
identifying peaks within |
span |
The window width, the default value is 3, meaning compare each
value to both of its neighbors. The value for |
ties |
a character indicating how to handle ties. See Details. |
ends |
a logical value indicating whether or not to include either the first or last observations in the sequence if it is a local maximum. |
Possible values for ties
include "none," which treats sequential tied values as
individual values; all other values can be thought of as collapsing
sequential tied values—"first," "middle," or "last" identify the first,
middle, or last, respectively, of a sequence of ties as the peak if appropriate.
A vector matching x
of logical values indicating whether the
corresponding element is a local maximum or not.
A peak is defined as an element in a sequence that is strictly greater
than all other elements within a window of width span
centered at that
element. As such, setting ties
to "none" has the effect of not
identifying peaks with sequential tied values.
max
# Note the effect of missing values peaks(c(1:6,5,4,NA,4,6,9,NA)) peaks(c(1:6,NA,5,4,NA,4,6,9,NA)) # Note the effect of ties peaks(c(1:6,6,6,5,4,3,4,6,9)) peaks(c(1:6,6,6,5,4,3,4,6,9), ties="none")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.