Used internally, to find the index of the value in a vector nearest to a target value, possibly in a specific preferred direction.
which_nearest(values, target, dir)
Single integer, the index of the value closest to target
according
to dir
.
numeric vector, the values considered.
single numeric value, the target to find the value closest to.
single numeric value. If 0
(the default), finds the index of the
value closest to the target, regardless of the direction. If < 0
or
> 0
, finds the index of the value closest to the target, but only
considers values at or below/above target, respectfully, if any (otherwise
returns the closest value regardless of direction).