0

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.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
msobo
  • 1
  • If you could include some of your data into the question (you could do something like dput(head(data, 10)) and paste the output) and also provide an example of the desired result, it would easier for folks to help. – user2474226 Nov 01 '19 at 16:09
  • Please provide a [reproducible minimal example](https://stackoverflow.com/q/5963269/8107362) – mnist Nov 01 '19 at 22:03

0 Answers0