title: R - cumulative sum by condition
body: <p>So I have a dataset which simplified looks something like this:</p>
  
  <pre><code>Year    ID     Sum
  2009    999    100
  2009    123     85
  2009    666    100
  2009    999    100
  2009    123     90
  2009    666     85
  2010    999    100
  2010    123    100
  2010    666     95
  2010    999     75
  2010    123    100
  2010    666     85
  </code></pre>
  
  <p>I'd like to add a column with the cumulative sum, by year and ID. Like this:</p>
  
  <pre><code>Year     ID     Sum    Cum.Sum
  2009    999     100        100
  2009    123      85         85  
  2009    666     100        100  
  2009    999     100        200
  2009    123      90        175
  2009    666      85        185
  2010    999     100        100
  2010    123     100        100
  2010    666      95         95
  2010    999      75        175
  2010    123     100        200
  2010    666      85        180
  </code></pre>
  
  <p>I think this should be pretty straight-forward, but somehow I haven't been able to figure it out. How do I do this? Thanks for the help!</p>