title: Count number of elements meeting criteria in columns with NA values
body: <p>I've got a matrix with "A", "B" and <code>NA</code> values, and I would like to count the number of "A" or "B" or <code>NA</code> values in every column.</p>
  
  <pre><code>sum(mydata[ , i] == "A")
  </code></pre>
  
  <p>and</p>
  
  <pre><code>sum(mydata[ , i] == "B")
  </code></pre>
  
  <p>worked fine for columns without <code>NA</code>. For columns that contain <code>NA</code> I can count the number of <code>NA</code>s with <code>sum(is.na(mydata[ , i])</code>. In these columns <code>sum(mydata[ , i] == "A")</code> returns <code>NA</code> as a result instead of a number.</p>
  
  <p>How can i count the number of "A" values in columns which contain <code>NA</code> values?</p>
  
  <p>Thanks for your help!</p>
  
  <p>Example:</p>
  
  <pre><code>&gt; mydata
      V1  V2  V3  V4 
  V2 "A" "A" "A" "A"
  V3 "A" "A" "A" "A"
  V4 "B" "B" NA  NA 
  V5 "A" "A" "A" "A"
  V6 "B" "A" "A" "A"
  V7 "B" "A" "A" "A"
  V8 "A" "A" "A" "A"
  
  sum(mydata[ , 2] == "A")
  # [1] 6
  
  sum(mydata[ , 3] == "A")
  # [1] NA
  
  sum(is.na(mydata[ , 3]))
  # [1] 1
  </code></pre>