aggregating data frames by sum
dataframe, r
Solution
In addition to `aggregate`, there is also `xtabs` which is designed specifically for summing up tables.
xtabs(Freq ~ Var1, data=rbind(d1, d2))
Problem
Say I have two data frames as follows. ``` d1 = data.frame(table(c(1,2,2,2,4,5))) d2 = data.frame(table(c(2,2,2,6))) ``` Combing the frames with `rbind` gives the following: ``` > rbind(d1, d2) Var1 Freq 1 1 1 2 2 3 3 4 1 4 5 1 5 2 3 6 5 1 ``` But what I would like is to calculate the sum of the `Freq` values with the same `Var1`, i.e. get ``` Var1 Freq 1 1 1 2 2 6 3 4 1 4 5 1 5 6 1 ``` How can I accomplish this?