I have a big data.frame that I want to aggregate by groupings of categorical variables in another. One method would be:
cars = mtcars
carb_grps = data.frame(carb = 1:8, carb_grp = rep(c('Low','Mid','High'), c(2,2,4)))
cars = merge(cars, carb_grps, by = 'carb')
aggregate(mpg ~ carb_grp, cars, mean)
carb_grp mpg
1 High 17.35000
2 Low 23.61176
3 Mid 15.90769
But this replicates all the carb_grp
details in the large data.table, which I'm guessing ties up more memory? I wonder if there's a more elegant/efficient way in R to achieve this?