title: add new rows from combination of multiple rows
body: <p>I am trying to add various columns together to add new rows to the end of a data frame, df, if conditions are met. </p>
  
  <pre><code>SurveyYear State Stratum Plot species pairs males_24 tib
  1       2015    CT      12    4    MALL     0        0   1
  2       2015    CT      12    4    ABDU     1        2   4
  3       2015    CT      12    4    AGWT     1        0   0
  4       2015    CT      11    2    ABDU     2        1   2
  5       2015    CT      11    2    MALL     0        1   0
  6       2015    CT      11    2    ABDU     4        4   7
  </code></pre>
  
  <p>For each grouped State, Stratum, and Plot I want to add a row to df with the sum of pairs, males_24, and tib. This needs to be done by groups of species to make a new species "TODU". In this case add up all species = ABDU and AGWT (actual data set has about 8 species to add up and 4 to not include). So there would be 2 new rows (keeping all others still) added to df that are:</p>
  
  <pre><code>2015 CT 12 4 TODU 2 2 4
  2015 CT 11 2 TODU 6 5 9
  </code></pre>
  
  <p>I can append rows easy enough manually, or adding a single column using</p>
  
  <pre><code>df[nrow(df) + 1, ] &lt;- c(,)
  </code></pre>
  
  <p>But I'm having a hard time figuring out how to group and sum while keeping the remainder of the data set intact and doing this for many variations. In SAS I would do this using proc sort, but I don't think I should need to sort first using R. Any help would be greatly appreciated. Thanks.</p>