| findPeaks | R Documentation |
A bare-bones, very fast function to find local maxima (peaks) in a numeric vector. NAs are set to the minimum value of input and effectively ignored. The first and last values can also be peaks. Plateaus are NOT treated as peaks.
findPeaks(
x,
wl = 3,
thres = NULL,
thresRel = NULL,
dropFirstLast = FALSE,
plot = FALSE
)
x |
numeric vector |
wl |
rolling window over which we look for maxima: central value ± floor(wl/2), eg ±1 if wl=3; forced to be at least 3 |
thres |
required absolute value of each peak |
thresRel |
required absolute excess over the window mean excluding the focal point |
dropFirstLast |
if TRUE, the first and last value cannot be peaks (only two-sided maxima accepted) |
plot |
if TRUE, plots the input vector with peaks marked. |
A vector of indices of local maxima.
x = c(5, 2, 3, 3, 2, 7, 3, 2, 5, 5, 1, 0, 2, NA)
findPeaks(x, wl = 3, plot = TRUE)
findPeaks(x, wl = 3, thres = 2, plot = TRUE)
findPeaks(x, wl = 3, thres = 100, plot = TRUE)
findPeaks(x, wl = 4, plot = TRUE)
findPeaks(x, wl = 6, plot = TRUE)
findPeaks(x, wl = 3, thresRel = 2, plot = TRUE)
findPeaks(x, wl = 3, thresRel = 4, plot = TRUE)
findPeaks(x, wl = 3, thres = 6, thresRel = 2, plot = TRUE)
findPeaks(x, dropFirstLast = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.