Skip to content
Prev 33619 / 398513 Next

Using weighted.mean() in aggregate()

On Sat, 21 Jun 2003 18:02:01 -0700
Spencer Graves <spencer.graves at pdf.com> wrote:

            
Here are two other ways, using the Hmisc package summarize or mApply functions, which can take a matrix as their first argument.  summarize returns a dataframe, mApply a vector

g <- function(y) wtd.mean(y[,1],y[,2])
summarize(cbind(y, wts), llist(sex,race), g, stat.name='y')
mApply(cbind(y,wts), llist(sex,race), g)

Frank Harrell
---
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat