#
# Make up two vectors
#
a <- c(1,2,3)
vect <- c(3,2,1)
#
# Now see on which index are the two closest in value
#
which.min.diff(a,vect)
#[1] 2
#
# ie its the second index where both vectors are actually 2
Run the code above in your browser using DataLab