Alternatively, you can use ddply from the plyr package:
require(plyr) ddply(df,.(id,age),summarise,no = sum(no))
In this particular example, the results are identical. However, this is not always the case; the difference between the two functions is described here . Both functions have their uses and are worth exploring, so I thought that this alternative should be mentioned.
source share