I'm trying to calculate asset-weighted returns by asset class. For the life of me, I can't figure out how to do it using the aggregate command.
My data frame looks like this
dat <- data.frame(company, fundname, assetclass, return, assets)
I'm trying to do something like (don't copy this, it's wrong):
aggregate(dat, list(dat$assetclass), weighted.mean, w=(dat$return, dat$assets))