Not quite sure how it will behave with your volume, but it cutruns pretty quickly.
The idea is to cut out the vector ain the media between the elements b.
Please note that I assume that the elements in bstrictly increase!
- :
a <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
b <- c(4,6,10,16)
cuts <- c(-Inf, b[-1]-diff(b)/2, Inf)
cut(a, breaks=cuts, labels=b)
, , findInterval (, , , ).
findInterval(a, cuts)
[1] 1 1 1 1 2 2 2 3 3 3 3 3 4 4 4
, - :
index = findInterval(a, cuts)
b[index]
, , a, b, cut ( findInterval), . .