I have a sorted array of values and a single value like so:
x <- c(1.0, 3.45, 5.23, 7.3, 12.5, 23.45)
v <- 6.45
I can find the index of the value after which v would be inserted into x while maintaining the sorting order:
max(which(x <= v))
[1] 3
It is nice and compact code, but I have the gut feeling that behind-the-scenes this is really inefficient: since which() does not know that the array is sorted it has to inspect all values.
Is there a better way of finding this index value?
Note: I am not interested in actually merging v into x. I just want the index value.
