title: How to count TRUE values in a logical vector
body: <p>In R, what is the most efficient/idiomatic way to count the number of <code>TRUE</code> values in a logical vector? I can think of two ways:</p>
  
  <pre><code>z &lt;- sample(c(TRUE, FALSE), 1000, rep = TRUE)
  sum(z)
  # [1] 498
  
  table(z)["TRUE"]
  # TRUE 
  #  498 
  </code></pre>
  
  <p>Which do you prefer? Is there anything even better?</p>