Find zero crossings of a vector, i.e., indices when the numeric variable crosses 0.

zero_crossings(x)

Arguments

x

A numeric vector.

Value

Vector of zero crossings.

See also

Based on the uniroot.all function from the rootSolve package.

Examples

x <- sin(seq(0, 4 * pi, length.out = 100))
plot(x)

zero_crossings(x)
#> [1]  1.00000 25.74975 50.50000 75.25025