I have two vectors with several thousand points, but they are generalized here:
A <- c(10, 20, 30, 40, 50) b <- c(13, 17, 20)
How to get signs A that are closest to b ? The expected result will be c(1, 2, 2) .
I know that findInterval can only find the first occurrence, not the nearest one, and I know which.min(abs(b[2] - A)) getting warmer, but I cannot figure out how to vectorize it to work with long vectors of both A and b .
source share