Displaying 1 result from an estimated 1 matches for "myweek".
Did you mean:
yweek
2012 Jul 17
1
weighted mean by week
...s ugly to me - it's full of loops.
I am sure there is a much more elegant and shorter way to do it.
Thanks a lot for any hints!
Dimitri
# I have a data frame:
x<-data.frame(group=c("group1","group2","group1","group2"),
myweight=c(0.4,0.6,0.4,0.6),
myweek=as.Date(c("2012-07-09","2012-07-09","2012-07-16","2012-07-16")),
var1=c(1,10,2,20),var2=c(10,1,20,2))
(x)
# For each week in "myweek", I'd like to build a weighted mean for
var1 and var2 - using "myweight" as weight.
# Below is my...