[R] weighted mean and by() with two index

2009-04-13 Thread Dong H. Oh
Hi expeRts, I would like to calculate weighted mean by two factors. My code is as follows: R tmp - by(re$meta.sales.lkm[, c(pc, sales)], re$meta.sales.lkm[, c(size, yr)], function(x) weighted.mean(x[,1], x[,2])) The result is as follows: R tmp size:

Re: [R] weighted mean and by() with two index

2009-04-13 Thread Mike Lawrence
Sounds like a job for plyr: http://had.co.nz/plyr On Mon, Apr 13, 2009 at 7:56 PM, Dong H. Oh r.arec...@gmail.com wrote: Hi expeRts, I would like to calculate weighted mean by two factors. My code is as follows: R tmp - by(re$meta.sales.lkm[, c(pc, sales)],                      

Re: [R] weighted mean and by() with two index

2009-04-13 Thread Frank E Harrell Jr
Also see the help file for the wtd.mean function in the Hmisc package, which has an example using the summarize function to do this. Frank Mike Lawrence wrote: Sounds like a job for plyr: http://had.co.nz/plyr On Mon, Apr 13, 2009 at 7:56 PM, Dong H. Oh r.arec...@gmail.com wrote: Hi

Re: [R] weighted mean and by() with two index

2009-04-13 Thread William Dunlap
Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com --- R] weighted mean and by() with two index Dong H. Oh r.arecibo at gmail.com Tue Apr 14 00:56:28 CEST 2009 Hi expeRts, I would like to calculate weighted mean by two factors. My code