So I have a dataset which simplified looks something like this:
Year ID Sum 2009 999 100 2009 123 85 2009 666 100 2009 999 10
Another way
1) use ddply to sum a variable by group (similar to SQL group by)
X <- ddply ( dataset, .(Year,ID), sum)
2) merge the result with dataset
Y <- merge( dataset, X, by=('Year','ID')