title: Dataframe with many years and annual totals [R]
body: <p>I have a large dataframe (AT_df) with many years for many countries, but no annual totals. The initial dataset has already been slimmed down to Pollutant_name (x1="CO2"), I dropped all subcategories, and to one country.</p>
  
  <p>I am preparing this data to afterwards run ggplot2, but for this I need to add a row for each year with the total of the categories (=1-6).</p>
  
  <p>The data looks like this (excerpt):</p>
  
  <pre><code>       x     y          x1      x2      x4   x6
  1553   1993  0.00000    CO2     Austria  6   6 - Other Sector
  1554   2006  0.00000    CO2     Austria  6   6 - Other Sector
  1555   2015  0.00000    CO2     Austria  6   6 - Other Sector
  2243   1998  12.07760   CO2     Austria  5   5 - Waste management
  2400   1992  11.12720   CO2     Austria  5   5 - Waste management
  2401   1995  11.11040   CO2     Austria  5   5 - Waste management
  2402   2006  10.26000   CO2     Austria  5   5 - Waste management
  2489   1998  0.00000    CO2     Austria  6   6 - Other Sector
  </code></pre>
  
  <p>I would like to insert a row which is labelled (x6= aggregate) and sums up the values for y (emissions) under the condition of x= year xyz &amp; x2=country_xyz. </p>
  
  <p>Basically something like this </p>
  
  <pre><code>sum(AT_df, x4 %in% c("1", "2", "3", "4", "5", "6") &amp; x ="yearxyz" &amp; 
  x2="Austria"). 
  </code></pre>
  
  <p>This then should be inserted into the dataframe FOR EACH YEAR (16 years in total)</p>
  
  <p>While I have tried some things I've read on stackoverflow, such as: </p>
  
  <pre><code>rbind(AT_df, data.frame(x1='Aggregate', y = sum(AT_df$y)))
  </code></pre>
  
  <p>... I was not able to write any correctly working code</p>
  
  <p>Thanks in any case and for any sort of help.</p>