I will try to explain my goal the best way possible.
Let's say I have two vectors:
Teffs <- c(6000, 6100, 6200, ..., 7500)
Ls <- c(40, 41, 42, 43, 44, ..., 60)
I want to find what elements in the vectors give values closest to the point (6199, 42.1). The index of Teffs MUST be the same as the index in Ls, otherwise I could easily index each vector individually using something like:
values <- c(6199, 42.1)
indexa <- which.min(abs(Teffs - values[1]))
indexb <- which.min(abs(Ls - values[2]))
indexa
3
indexb
3
In this scenario, it is obvious the third elements in the vector give the closest values to the desired point. However, what if it was more ambigous? What if the point I wanted to find indices closest to was (6200, 62) or (6800, 59) or even (6000, 60)? How would I go about this while maintaining that the index in Teffs is the same as in Ls?
question from:
https://stackoverflow.com/questions/65946559/what-is-the-best-way-to-find-the-index-of-two-vectors-whose-values-are-closest-t 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…