title: Why is the R match function so slow?
body: <p>The following should find the location of the first instance of the integer <code>1</code>:</p>
  
  <pre><code>array &lt;- rep(1,10000000)
  system.time(match(1,array))
  </code></pre>
  
  <p>This returns</p>
  
  <pre><code>   user  system elapsed
    0.720   1.243   1.964
  </code></pre>
  
  <p>If I run the same task using an array of size <code>100</code> I get this:</p>
  
  <pre><code>   user  system elapsed
        0       0       0
  </code></pre>
  
  <p>Since all it should be doing is looking at the first value in the array and returning a match, the time taken should be that of a lookup and a comparison, regardless of the size of the array. If I wrote this in lower-level language it would cost in the order of a handful of clock cycles (a microsecond or less?) regardless of the array size. Why does it take a second in R? It seems to be iterating through he whole array...</p>
  
  <p>Is there a way for it to abort once it has found its match, rather than continuing to iterate unnecessarily?</p>