nearest: Calculate the nearest element in a vector as compared to a...

nearestR Documentation

Calculate the nearest element in a vector as compared to a reference value

Description

the nearest function returns the position of a vector that is closest to a defined value by determining the element with the smallest squared distance.

Usage

nearest(value, lookup_vector)

Arguments

value

A numeric reference value

lookup_vector

The vector to compare to the reference value

Value

Vector element index of nearest value

Examples

set.seed(1)
x <- runif(10, min=0, max=100)
res <- nearest(50, x)
plot(x)
abline(h=50, col=8, lty=2)
points(res, x[res], pch=20, col=2)


marchtaylor/sinkr documentation built on July 4, 2022, 5:48 p.m.