localMax: Calculate local maximum within a local neighborhood

Description Usage Arguments Details Value Examples

View source: R/localMax.R

Description

Calculate local maximum within a local neighborhood

Usage

1
localMax(vec, neighborhood)

Arguments

vec

a vector to be evaluated for the presence of local maxima

neighborhood

number of points to the left and right of a point for calculating local maxima (see details).

Details

'neighborhood = 1' will detect local maxima at position 'i' defind as a point that is greater than both its neighbors to the left '(i-1)' and right '(i+1)'. Setting 'neighborhood > 1' results in detecting local maxima at a position 'i' defined as a point that is greater than all neighboring points to the left 'c(i-1, i-..., i-n)' and right 'c(i+1, i+..., i+n)'.

Value

a logical vector masking the positions of local maxima

Examples

1
2
3
4
5
6
7
8
dat <- rnorm(n = 100, mean = 0, sd = 1)
i <- seq_along(dat)
locMax <- localMax(vec = dat, neighborhood = 1)

i_locMax <- i[locMax]
locMax <-dat[locMax]

plot(x = i, y = dat); points(x = i_locMax, y = locMax, col = "red")

pmbrophy/SummitR documentation built on May 20, 2020, 12:36 a.m.