Description Usage Arguments Value See Also Examples
Finds both local extrema in a vector, time series, or in each column of a matrix.
1 | msExtrema(x, span=3)
|
x |
a vector, time series, or matrix. If |
span |
a numeric value indicating the span of the local extreme. A local maximum (minimum) is defined as an element in a sequence which is greater (smaller) than all other elements within a window of width span centered at that element. The default value is 3, meaning that a maximum (minimum) is bigger (smaller) than both of its neighbors. |
a list with two elements:
index.max |
an object like x of logical values. Values that are TRUE correspond to local maxima in the data. |
index.min |
an object like x of logical values. Values that are TRUE correspond to local minima in the data. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## create a synthetic sequence
a<-c(3,3,2,1,1,2,1,2,3,3,1,1,1,3,3,3,2,2,2,1,1,1,1,2,3)
## detect local maxima and minima
maxmin <- msExtrema(a)
## visualize the result
par(mfrow=c(1,1))
plot(a, type="l")
points((1:length(a))[maxmin$index.max],
a[maxmin$index.max], col=2, pch=1)
points((1:length(a))[maxmin$index.min],
a[maxmin$index.min], col=3, pch=2)
if (!is.R()){
legend(x=18, y=3, col=2:3, marks=1:2, legend=c("maxima", "minima"))
} else {
legend(x=18, y=3, col=2:3, pch=1:2, legend=c("maxima", "minima"))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.