set.seed(1234)
.x <- c(rnorm(100, 2, 1), rnorm(100, 9, 1))
tpi <- do_find_turning_points(.x, .return = "index", .adjust = 1)
dx <- density(.x, adjust = 1, n = length(.x))
plot(dx)
points(dx$x[tpi$maxima], dx$y[tpi$maxima], pch = 19, col = "red")
points(dx$x[tpi$minima], dx$y[tpi$minima], pch = 19, col = "blue")
do_find_turning_points(.x, .return = "value", .adjust = 1)
Run the code above in your browser using DataLab