which.closest function

which.closest find a number in a vector closest to a given value