locmax: Local Maxima

Description Usage Arguments Details Value Author(s) Examples

View source: R/utils.R

Description

Find the indices of the local maxima of a vector.

Usage

1
locmax(x, halfWindow = 2, findLimits = FALSE)

Arguments

x

A numeric vector.

halfWindow

The number of vector elements to look on either side of an element before considering it a local maximum.

findLimits

If TRUE, then also return the approximate boundaries of the peak.

Details

For this function, a local maximum is defined as an element greater than all of the elements within halfWindow elements to the left of it, and greater than or equal to all of the elements within halfWindow elements to the right of it.

The boundaries are found by descending the local maxima until the elements are no longer non-increasing. Small increases within halfWindow of the local maxima are ignored.

Value

An integer vector giving the indices of the local maxima, potentially with attributes 'lower' and 'upper' if findLimits=TRUE.

Author(s)

Kylie A. Bemis

Examples

1
2
3
x <- c(0, 1, 1, 2, 3, 2, 1, 4, 5, 1, 1, 0)

locmax(x, findLimits=TRUE)

matter documentation built on Nov. 8, 2020, 6:15 p.m.