title: R: scan vectors once instead of 4 times?
body: <p>Suppose I have two equal length logical vectors.
  Computing the <a href="http://en.wikipedia.org/wiki/Confusion_matrix" rel="nofollow">confusion matrix</a> the easy way:</p>
  
  <pre><code>c(sum(actual == 1 &amp; predicted == 1),
    sum(actual == 0 &amp; predicted == 1),
    sum(actual == 1 &amp; predicted == 0),
    sum(actual == 0 &amp; predicted == 0))
  </code></pre>
  
  <p>requires scanning the vectors <strong>4</strong> times.</p>
  
  <p>Is it possible to do that in a single pass?</p>
  
  <p>PS. I tried <code>table(2*actual+predicted)</code> and <code>table(actual,predicted)</code> but both are obviously much slower.</p>
  
  <p>PPS. Speed is not my main consideration here, I am more interested in understanding the language.</p>