Description Usage Arguments Value Examples
Fast detection of local maxima and minima of a numeric vector. This function takes a numeric vector as input and returns a logical vector with the same length and TRUE values at local maxima/minima (depending on function). If multiple succeeding values at a local maximum/minimum are equal, then only the center (rounded up if necessary) of the maximum/minimum is marked with TRUE.
1 2 3 | flag_maxima_positions(values)
flag_minima_positions(values)
|
values |
numeric vector of values |
logical vector with TRUE at the center of local maxima/minima
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | var <- c(1,2,3,3,2,1,4,5,6,7,5,4,3)
## Using the Maxima functions
flag_maxima_positions(var)
# values of maxima
var[flag_maxima_positions(var)]
# indices of maxima
which(flag_maxima_positions(var))
## Using the Minima functions
flag_minima_positions(var)
# values of maxima
var[flag_minima_positions(var)]
# indices of maxima
which(flag_minima_positions(var))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.