title: Match values to nearest value in another array in R
body: <p>I need to match a value to its nearest corresponding value in R and extract its index.</p>
  
  <p>The command <code>FindInterval(value,array)</code> achieves this but only works if the array is in ascending order.</p>
  
  <p>The command <code>match(value,array)</code> only works if the value provides an exact match to one in the array.</p>
  
  <p>For example,</p>
  
  <pre><code>array &lt;- c(0.1,0.5,0.6,0.3,0.9,1.4,0.45)
  value &lt;- 0.47
  </code></pre>
  
  <p>I'd like a command which then matches this to the nearest corresponding <code>value</code> (here 0.45) and returns the <code>index</code> (here 7).</p>