locmax {matter} | R Documentation

## Local Maxima

### Description

Find the indices of the local maxima of a vector.

### Usage

    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

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

    locmax(x, findLimits=TRUE)

[Package matter version 1.16.0 Index]