title: Vectorization of findInterval()
body: <p>I have following problem with R function findInterval()</p>
  
  <p>Given a vector X and a matrix Y, I want to find in which interval lie elements of X. Intervals are constructed, having breakpoints in Y rows. In other words for X = c(2,3) and Y =  matrix(c(3,1,4,2,5,4),2,3), the output would be c(0,2). I wrote following code:</p>
  
  <pre><code>X &lt;- c(2,3)
  Y &lt;- matrix(c(3,1,4,2,5,4),2,3)
  
  output &lt;- diag(apply(Y,1,function(z)findInterval(X,z)))
  </code></pre>
  
  <p>and it works. However, I think, it can be optimised, since the apply function returns 2 x 2 matrix (that's why i had to get diagonal of that). Is there a way to do the same, but using function, which will return a vector, taking as an argument my vector X and matrix Y? I perform this operation on high-demensional vectors, so obtaining unnecessary matrixes size 10000 x 10000 is not a good idea imho. To maximize efficiency, I don't want to use loops.</p>
  
  <p>Thanks in advance for any feedback.</p>