dat=data.frame(
year=c(rep(2007,5),rep(2008,3),rep(2009,3)),
province=c("a","a","b","c","d","a","c","d","b","c","d"),
sale=1:11)
tapply(dat$sale,list(dat$year,dat$province),sum)
a b c d
2007 3 3 4 5
2008 6 NA 7 8
2009 NA 9 10 11
In the case , how can i change the tapply into aggregate to get the same result?