[R] Stratified weighted statistics

Frank E Harrell Jr f.harrell at vanderbilt.edu
Wed Aug 29 13:58:58 CEST 2007

Vikas Rawal wrote:
> I need to compute weighted descriptive statistics (mean, median,
> variance) for a vector of data disaggregated by a set of index
> variables. The weights to be used are vector in the same data frame
> and have to be disaggregated by the same index variables.
> Package Hmisc has functions for computing weighted statistics. But
> both by/aggregate and summarise (in Hmisc) allow a function to have
> only a simgle argument. In my case, I need to specify by the variable
> and the weights as argument to the function.
> Could anyone please advice how to do it.

Please look again at the help files for summarize and wtd.mean which 
show how to do this.


> As an example, say I have a data.frame giving incomes of persons in
> different towns along with weights to be given for each sampled
> person. How will I compute weighted statistics for each town?
> Vikas Rawal
> JNU, New Delhi.
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University

More information about the R-help mailing list