title: How to find a total of row values in R
body: <p>I am trying to find the total of rows that have a column value of 3 or 4. That being said, the first row has only one value of 3 so if I create a new column</p>
  <pre><code>currentdx_count1$TotalDiagnoses
  </code></pre>
  <p>That new column called TotalDiagnoses should only have a value of 1 under it for the first row. I have tried</p>
  <pre><code>currentdx_count1$TotalDiagnoses &lt;- rowSums(currentdx_count1[2:32])
  </code></pre>
  <p>This doesn't give me what I need as expected because it literally sums up the whole row. That being said, is there an existing function that does what I want to do or will I have to make one? Could I specify more in rowSums for it to work as I need it to?</p>
  <p>Thanks for any and all help.</p>
  <p>Edit: I'm trying to adapt a method I use earlier in my script that works for a similar purpose</p>
  <pre><code>findtotal &lt;- endsWith(names(currentdx_count1), 'Current')
  findtotal &lt;- lapply(findtotal, `&gt;`, 2)
  findtotal &lt;- unlist(findtotal)
  currentdx_count1$TotalDiagnoses &lt;- currentdx_count1[c(findtotal)]
  </code></pre>
  <p>I get an error which I have never seen before (an error in view?!)
  So I tried just this</p>
  <pre><code>findtotal &lt;- endsWith(names(currentdx_count1), 'Current')
  currentdx_count1$TotalDiagnoses &lt;- currentdx_count1[c(findtotal)]
  </code></pre>
  <p>Gets me closer but it is finding the total count for each column separately which is not what I need. I want a single column to encompass counts for each SID.</p>