title: Counting number of instances of a condition per row R
body: <p>I have a large file with the first column being IDs, and the remaining 1304 columns being genotypes like below. </p>
  
  <pre><code>rsID    sample1    sample2    sample3...sample1304
  abcd    aa         bb         nc        nc
  efgh    nc         nc         nc        nc 
  ijkl    aa         ab         aa        nc 
  </code></pre>
  
  <p>I would like to count the number of "nc" values per row and output the result of that to another column so that I get the following:</p>
  
  <pre><code>rsID    sample1    sample2    sample3...sample1304    no_calls
  abcd    aa         bb         nc        nc            2
  efgh    nc         nc         nc        nc            4
  ijkl    aa         ab         aa        nc            1
  </code></pre>
  
  <p>The table function counts frequencies per column, not row and if I transpose the data to use in the table function, I would need the file to look like this:</p>
  
  <pre><code>abcd         aa[sample1]
  abcd         bb[sample2]
  abcd         nc[sample3] ...
  abcd         nc[sample1304]
  efgh         nc[sample1]
  efgh         nc[sample2]
  efgh         nc[sample3] ...
  efgh         nc[sample1304]
  </code></pre>
  
  <p>With this format, I would get the following which is what I want:</p>
  
  <pre><code>ID    nc   aa   ab   bb
  abcd  2    1    0    1
  efgh  4    0    0    0
  </code></pre>
  
  <p>Does anybody have any idea of an simple way to get frequencies by row? I am trying this right now, but it is taking quite some time to run:</p>
  
  <pre><code>rsids$Number_of_no_calls &lt;- apply(rsids, 1, function(x) sum(x=="NC"))
  </code></pre>