I have the following dataframe:
df = data.frame(date = c("26/06/2013", "26/06/2013", "26/06/2013", "27/06/2013", "27/06/2013", "27/06/2013", "28/06/2013", "28/06/2013", "28/06/2013"), return = c(".51", ".32", ".34", ".39", "1.1", "3.2", "2.1", "5.3", "2.1"), cap = c("500", "235", "392", "213", "134", "144", "232", "155", "213"), weight = c("0.443655723", "0.20851819", "0.347826087", "0.433808554", "0.272912424", "0.293279022", "0.386666667", "0.258333333", "0.355"))
I would like to calculate:
1) The last column of "weight". Which is the weights of the "cap" column PER DAY.
2) The weighted "cap" mean of "return" PER DAY. I want to get the following output:
result = data.frame(date = c("26/06/2013", "27/06/2013", "28/06/2013"), cap.weight.mean = c("0.411251109", "1.407881874", "2.926666667"))