aggregate(cbind(a,b) ~ year, data = y, sum) # year a b #1 2007 10 5 #2 2008 13 6 #3 2009 21 12 #4 2010 19 11