Dear Marc,

For the weighted mean, one possible solution is as follows
and will hopefully give you the general idea:

tmp <- data.frame(x=sample(1:5, 100, replace=TRUE), 
                  y=sample(1:100, 100, replace=TRUE),
                  w=runif(100))
lapply(split(tmp[, 2:3], tmp[, "x"]),
   function(x) { weighted.mean(x=x$y, w=x$w)})


Regards,

Andrew C. Ward

CAPE Centre
Department of Chemical Engineering
The University of Queensland
Brisbane Qld 4072 Australia


Quoting [EMAIL PROTECTED]:

> 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.
> 
>  
> 
> Thanks.
> 
>  
> 
> Marc
> 
>  
> 
>  
> 
>  
> 
>  
> 
> 
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to