title: Proper way to split data frames at multiple levels using ddply
body: <p>Let's say I have a data frame like the following:</p>
  
  <pre><code>  year stint  ID  W
  1 2003     1 abc 10
  2 2003     2 abc  3
  3 2003     1 def 16
  4 2004     1 abc 15
  5 2004     1 def 11
  6 2004     2 def  7
  </code></pre>
  
  <p>I would like to combine the data so that it looks like</p>
  
  <pre><code>  year  ID  W
  1 2003 abc 13
  3 2003 def 16
  4 2004 abc 15
  5 2004 def 18
  </code></pre>
  
  <p>I found a way to combine the data as desired, but I'm very sure that there's a better way.</p>
  
  <pre><code>combinedData = unique(ddply(data, "ID", function(x) {
      ddply(x, "year", function(y) {
          data.frame(ID=x$ID, W=sum(y$W))
      })
  }))
  combinedData[order(combinedData$year),]
  </code></pre>
  
  <p>This produces the following output:</p>
  
  <pre><code>   year  ID  W
  1  2003 abc 13
  7  2003 def 16
  4  2004 abc 15
  10 2004 def 18
  </code></pre>
  
  <p>Specifically I don't like that I had to use unique (otherwise I get each unique combo of year,ID,W three times in the outputted data), and I don't like that the row numbers aren't sequential. How can I do this more cleanly?</p>