# NOT RUN {
y <- c(0, 1, 2, 1, -1, 1:4, 5, 6, 0, -4, -6, -5:5, -2:2)
#y <- c(0, 0, 0, 1, -1, 1:4, 4, 4, 0, 0, 0, -5:5, -2:2, 2, 2)
#y <- c(0, 0, 0, 1, -1, 1:4, 4, 4, 0, 0, 0, -5:5, -2:2, 0, 0)
plot(y, type = "b"); abline(h = 0)
localextrema(y)
findextrema <- localextrema(y)
points(findextrema$maxindex, y[findextrema$maxindex], pch=16, col="red")
points(findextrema$minindex, y[findextrema$minindex], pch=16, col="blue")
# }
Run the code above in your browser using DataLab