return index from a vector of the value closest to a given element October 5, 2022 by Tarik I would use which.min which.min(abs(x-0.4)) This will return the first index of the closest number to 0.4.