find_peaks | R Documentation |
This function finds peaks (local maxima) in a numeric vector, using a user
selectable span and global and local size thresholds, returning a
logical
vector.
find_peaks(
x,
global.threshold = 0,
local.threshold = 0,
local.reference = "minimum",
threshold.range = NULL,
span = 3,
strict = FALSE,
na.rm = FALSE
)
x |
numeric vector. Hint: to find valleys, change the sign of the
argument with the unary operator |
global.threshold |
numeric A value between 0.0 and 1.0,
relative to |
local.threshold |
numeric A value between 0.0 and 1.0, relative to
|
local.reference |
character One of |
threshold.range |
numeric vector of length 2 or a longer vector or list
on which a call to |
span |
odd integer A peak is defined as an element in a sequence which
is greater than all other elements within a moving window of width
|
strict |
logical flag: if TRUE, an element must be strictly greater than all other values in its window to be considered a peak. Default: TRUE. |
na.rm |
logical indicating whether |
Function find_peaks
is a wrapper built onto function
peaks
from splus2R, adds support for peak
height thresholds and handles span = NULL
and non-finite (including
NA) values differently than splus2R::peaks
. Instead of giving an
error when na.rm = FALSE
and x
contains NA
values,
NA
values are replaced with the smallest finite value in x
.
span = NULL
is treated as a special case and selects max(x)
.
Two tests are optional, one based on the absolute height of the peaks
(global.threshold
) and another based on the height of the peaks
compared to other values within the window of width equal to span
(local.threshold
). The reference value used within each window
containing a peak is given by local.reference
. Parameter
threshold.range
determines how the values passed as argument to
global.threshold
and local.threshold
are scaled. The default,
NULL
uses the range of x
. Thresholds for ignoring too small
peaks are applied after peaks are searched for, and negative threshold
values can in some cases result in no peaks being returned.
While function find_peaks
accepts as input a numeric
vector
and returns a logical
vector, methods peaks
and
valleys
accept as input different R objects, including spectra and
collections of spectra and return a subset of the object. These methods
are implemented using calls to functions find_peaks
and
fit_peaks
.
A vector of logical values of the same length as x
. Values
that are TRUE correspond to local peaks in vector x
and can be used
to extract the rows corresponding to peaks from a data frame.
The default for parameter strict
is FALSE
in functions
peaks()
and find_peaks()
, as in stat_peaks()
and in
stat_valleys()
, while the default in peaks
is strict = TRUE
.
peaks
.
Other peaks and valleys functions:
find_spikes()
,
get_peaks()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()
with(sun.data, w.length[find_peaks(s.e.irrad)])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.