title: dplyr row sum on selected rows
body: <p>I have the following data:</p>
  
  <pre><code>library(dplyr)
  library(purrr)
  
   d &lt;- data.frame(
    Type= c("d", "e", "d", "e"),
    "2000"= c(1, 5, 1, 5),
    "2001" = c(2, 5 , 6, 4),
    "2002" = c(8, 9, 6, 3))
  </code></pre>
  
  <p>I would like to use rowsum and mutate to generate a new row which is the sum of 'd' and another row which is the sum of 'e' so that the data looks like this:</p>
  
  <pre><code>d2 &lt;- data.frame(
  Type= c("d", "e", "d", "e", "sum_of_d", "Sum_of_e"),
  "2000"= c(1, 5, 1, 5, 2, 10),
  "2001" = c(2, 5 , 6, 4, 8, 9),
  "2002" = c(8, 9, 6, 3, 14, 12))
  </code></pre>
  
  <p>I think the code should look something like this:</p>
  
  <pre><code>d %&gt;% 
   dplyr::mutate(sum_of_d = rowSums(d[1,3], na.rm = TRUE)) %&gt;% 
   dplyr::mutate(sum_of_e = rowSums(d[2,4], na.rm = TRUE)) -&gt; d2
  </code></pre>
  
  <p>however this does not quite work. Any ideas? </p>
  
  <p>Thanks</p>