which.closest: which.closest find the number closest to a given value

View source: R/rutils.R

which.closestR Documentation

which.closest find the number closest to a given value

Description

which.closest finds either the number in a vector which is closest to the input value or its index value

Usage

which.closest(x, invect, index = T)

Arguments

x

the value to lookup

invect

the vector in which to lookup the value x

index

should the closest value be returned or its index; default=TRUE

Value

by default it returns the index in the vector of the value closest to the input value

Examples

## Not run: 
vals <- rnorm(100,mean=5,sd=2)
pick <- which.closest(5.0,vals,index=TRUE)
pick
vals[pick]
which.closest(5.0,vals,index=FALSE)

## End(Not run)

haddonm/codeutils documentation built on April 15, 2024, 1:02 p.m.