title: R/dplyr: Grouping and mutating problem with sum function
body: <p>I am working with a data set of planes in certain air corridors across different years, <code>df</code> looks something like this:</p>
  <pre><code>ID   Airline  Corridor Year Index_A
  1244 American C1       2010 0.03
  1253 Delta    C12      2011 0.43
  1643 Delta    C1       2010 0.05
  1375 United   C1       2010 0.21
  1621 American C5       2016 0.02
  </code></pre>
  <p>Variable <code>Index_A</code> has a range of 0-1. <code>Corridor</code> is in factor format.</p>
  <p>I am trying to calculate the sum of <code>Index_A</code> for every <code>Year</code> <strong>and</strong> <code>Corridor</code>. <code>Index_A</code> is set up in a way that for every <code>Year</code> <strong>and</strong> <code>Corridor</code> its sum must be less than 1.</p>
  <p>This is where I am having trouble with my code. It looks like this:</p>
  <pre><code>df_final %&gt;% group_by(Corridor, Year) %&gt;%
                  mutate(total = sum(Index_A)) %&gt;% ungroup(Corridor, Year)
  </code></pre>
  <p>The problem is that for certain years <code>total</code> is outside the range, i.e. &gt;1. I am not sure what I am doing wrong and how to address the issue.</p>
  <p>Am I looking at this wrong? I'd appreciate any help and don't have a package preference. Thank you.</p>