do_find_turning_points: Find turning points

View source: R/turning_points.R

do_find_turning_pointsR Documentation

Find turning points

Description

Find turning points (minima and maxima) in a vector.

Usage

do_find_turning_points(.x, .return = c("value", "index"), .adjust = 1.5, ...)

Arguments

.x

A numeric vector

.return

A character giving the desired return type.

.adjust

A numeric giving the adjustment to the adjust argument of stats::density().

...

Other parameters passed to stats::density()

Value

A list with the two elements maxima and minima

Examples

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)

beadplexr documentation built on July 9, 2023, 5:59 p.m.