Re: [R] Weighted Average on More than One Variable in Data Frame

2011-09-21 Thread StellathePug
Thanks Jean, that worked perfectly! Try this sapply(split(df, df$g), function(x) apply(x[, 1:2], 2, weighted.mean, x$w)) Jean StellathePug wrote on 09/21/2011 01:15:33 PM: > > I have a data frame, say df, which has 4 variables, one of which I would > like to use as a grouping variable (g), an

Re: [R] Weighted Average on More than One Variable in Data Frame

2011-09-21 Thread Jean V Adams
Try this sapply(split(df, df$g), function(x) apply(x[, 1:2], 2, weighted.mean, x$w)) Jean StellathePug wrote on 09/21/2011 01:15:33 PM: > > Dear R Users, > I have looked for a solution to the following problem and I have not been > able to find it on the archive, through Google or in the R

[R] Weighted Average on More than One Variable in Data Frame

2011-09-21 Thread StellathePug
Dear R Users, I have looked for a solution to the following problem and I have not been able to find it on the archive, through Google or in the R documentation. I have a data frame, say df, which has 4 variables, one of which I would like to use as a grouping variable (g), another one that I woul