title: Fastest way to find nearest value in vector
body: <p>I have two integer/posixct vectors:</p>
  <pre><code>a &lt;- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) #has &gt; 2 mil elements
  b &lt;- c(4,6,10,16) # 200000 elements
  </code></pre>
  <p>Now my resulting vector c should contain for each element of vector a the nearest element of b:</p>
  <pre><code>c &lt;- c(4,4,4,4,4,6,6,...)
  </code></pre>
  <p>I tried it with <code>apply</code> and <code>which.min(abs(a - b))</code> but it's very very slow.</p>
  <p>Is there any more clever way to solve this? Is there a <code>data.table</code> solution?</p>