title: Using row indices values in matrix array to sum row values down column in a data frame in R - reproducible example
body: <p>I have a dataframe (df1) the contains a column of values. I also have a matrix (ma1) that contains two columns which refer to row indices in df1 (i.e., row 1, col 1 of ma1 is 4 and col 2 is 6 - these refer to row 4 and 6 of df1)</p>
  <p>I need to be able to use the row indices in ma1 to sum the values of rows in df1 for each window. So i need the output to be sum of row 4-6, row 9 to 12, row 15 to 19 etc. - which correspond with the indices values in ma1.</p>
  <p>I have read about rowSums but unsure how to full implement this in this example</p>
  <p>Example: ma1 row 1 is 4 and 6, so I need output to be sum of rows 4,5,6 of df1. i.e., 3.37 + 0 + 1.19. Row 2 of ma1 is 9 and 12, so I need output to be sum of rows 9,10,11,12 of df1 etc etc</p>
  <pre><code>df1 &lt;- structure(list(CO2 = c(3.37, 0, 1.19, 0.889999999999986, 5.88999999999999, 
      0.169999999999959, 3.92000000000002, 1.46000000000004, 1.23000000000002, 
      2.60000000000002, 1.39999999999998, 0, 4.35999999999996, 0.649999999999977, 
      0.149999999999977, 2.08999999999997, 4.23999999999995, 5.69, 
      0, 3.38, 1.95000000000005, 3.16999999999996, 2.82999999999998, 
      0, 1.69, 1.36000000000001, 0.669999999999959, 0.54000000000002, 
      0.529999999999973, 0.95999999999998, 0.600000000000023, 0.850000000000023, 
      0, 0.00999999999999091, 1.77999999999997, 1.98000000000002, 1.63, 
      2.74000000000001, 2.56, 3.50999999999999, 0, 0, 3.37, 0, 0.630000000000052, 
      0, 0.270000000000039, 0.769999999999982, 0.75, 1.25999999999999, 
      0, 0.689999999999998, 1.12, 0.210000000000036, 2.66000000000003, 
      3.14000000000004, 2.24000000000001, 0.620000000000005, 0.0900000000000318, 
      0)), row.names = c(NA, -60L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
      ))
  
      ma1 &lt;- structure(c(4, 6, 9, 12, 15, 19, 33, 37, 41, 54, 6, 9, 12, 15, 
      19, 24, 37, 41, 44, 60), .Dim = c(10L, 2L), .Dimnames = list(
          NULL, c(&quot;co2_start&quot;, &quot;co2_end&quot;)))
  </code></pre>