Learn R Programming

splus2R (version 1.0-1)

peaks: Local maxima

Description

Finds the local maxima in a vector, or time series, or in each column of a matrix.

Usage

peaks(x, span=3, strict=TRUE)

Arguments

x
vector or matrix.
span
a peak is defined as an element in a sequence which is greater than all other elements within a window of width span centered at that element. The default value is 3, meaning that a peak is bigger than both of its neighbors. Default: 3.
strict
logical flag: if TRUE, an element must be strictly greater than all other values in its window to be considered a peak. Default: TRUE.

Value

  • an object like x of logical values. Values that are TRUE correspond to local peaks in the data.

concept

splus

See Also

anyMissing, as.rectangular, colIds, colMaxs, colMedians, colMins, colRanges, colStdevs, colVars, deparseText, ifelse1, is.numeric.atomic.vector, is.rectangular, is.missing, is.zero, lowerCase, oldUnclass, numCols, numRows, positions, rowIds, rowMaxs, rmvnorm, stdev, subscript2d, upperCase, vecnorm, which.na.

Examples

Run this code
x <- as.vector(sunspots)
z <- peaks(x, span=51)
plot(x, type="l")
abline(v=which(z), col="red", lty="dashed")

Run the code above in your browser using DataLab