[R] weighted mean

Jason Turner jasont at indigoindustrial.co.nz
Wed Nov 26 00:39:42 CET 2003


MZodet at ahrq.gov wrote:

> How do I go about generating a WEIGHTED mean (and standard error) of a
> variable (e.g., expenditures) for each level of a categorical variable
> (e.g., geographic region)?  I'm looking for something comparable to PROC
> MEANS in SAS with both a class and weight statement.

That's two questions.
1) to apply a weighted mean to a vector, see ?weighted.mean

2) to apply a function to data grouped by categorical variable, you 
probably need "by" or "tapply".  See the help pages and examples for both.

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
http://www.indigoindustrial.co.nz
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list