I'm fairly new to the world of R and have difficulty with the following issue:
I have a data frame of three columns - dates, stock weights and factor exposure- and, for each date, I would like to sum up all stocks weights of every stock based on their assigned yield quintile group. The output would be a "rows (dates) x columns (quintiles 1-5 groups)" vector of stock weights.
I have gotten this far:
quintiles <- quantile(secwgtexp$fac_exp, seq(0, 1, by=0.20), na.rm=TRUE)
bins <- cut(secwgtexp$fac_exp, quintiles, include.lowest=TRUE,
labels=c("20%", "40%", "60%", "80%", "100%"))
data.frame(X=secwgtexp$fac_exp, Bin=bins)
However I think quintile assignments are being done based on the entire time-series of stocks' values and I would like the assignment based on date. I was thinking of using ddply function for this but I get the following:
Error in llply(.data = .data, .fun = .fun, ..., .progress = .progress, :
.fun is not a function.""
Once I have figured out the quintile assignment by date, I will work towards summing by quintile assignment by date.
Any help and insights is greatly appreciated.