title: How to get the closest element in a vector for every element in another vector without duplicates?
body: <p>I got this code which create two vectors and for each element from <code>a</code> I want to get the closest element in <code>b</code> :</p>
  
  <pre><code>a = rnorm(100)
  b = rnorm(100)
  c = vapply(a, function(x) which.min(abs(b - x)), 1)
  table(duplicated(c))
  
  FALSE  TRUE 
     61    39 
  </code></pre>
  
  <p>As you can see this method is prompt to give a lot of duplicates which is normal but I would like to not have duplicates. I thought of deleting occurence from <code>b</code> once an index has been selected but I don't know how to do it under <code>vapply</code>.</p>