findPeaks | R Documentation |
Find local peaks in a distribution
findPeaks(x, m = 3)
x |
vector of value series |
m |
number of adjacent points needed to be lower to count as a peak |
use findPeaks(-x) to find troughs
vector of positions in x where there is a peak
x <- w <- rnorm(n = 100, mean = 0, sd = 1)
for (t in 2:100) { x[t] <- x[t - 1] + w[t] }
p3 <- findPeaks(x)
p10 <- findPeaks(x, 10)
t10 <- findPeaks(-x, 10)
plot(x, type = "l")
abline(v = p10, col = "green", lwd = 5)
abline(v = p3, col = "blue")
abline(v = t10, col = "red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.