nearest | R Documentation |
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.
nearest(value, lookup_vector)
value |
A numeric reference value |
lookup_vector |
The vector to compare to the reference value |
Vector element index of nearest value
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.