Skip to content

Instantly share code, notes, and snippets.

@alexpreynolds
Last active November 23, 2021 02:37
Show Gist options
  • Save alexpreynolds/6c7e86ad3e0d910164c8c296362c8ac8 to your computer and use it in GitHub Desktop.
Save alexpreynolds/6c7e86ad3e0d910164c8c296362c8ac8 to your computer and use it in GitHub Desktop.
Find local minima and maxima
install.packages("quantmod")
library("quantmod")
x <- seq(0, 2*pi, 0.1)
y <- sin(x)
y[findPeaks(y)]
# [1] 0.9916648
y[findPeaks(-y)]
# [1] -0.9961646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment