Displaying 1 result from an estimated 1 matches for "myweeks".
Did you mean:
myweek
2012 Jul 17
1
weighted mean by week
...012-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 inelegant code:
myweeks<-unique(x$myweek)
nr.of.weeks<-length(myweeks)
myvars<-c("var1","var2")
mylist<-NULL
for(i in 1:nr.of.weeks){ # i<-1
out<-NULL
for(var in myvars){ # var<-myvars[2]
temp.x<-x[x$myweek %in% myweeks[i],c("myweight",var)]
temp.out<-weig...