flag_maxima_positions: Detect local maxima/minima of a numeric vector

Description Usage Arguments Value Examples

Description

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.

Usage

1
2
3

Arguments

values

numeric vector of values

Value

logical vector with TRUE at the center of local maxima/minima

Examples

 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))

segmag documentation built on May 2, 2019, 2:46 a.m.