Hello R folks,

Reproducible code below - I'm trying to do a weighted mean by a factor and
can't figure it out.  Thanks in advance for your assistance.

Mike

data<-data.frame(c(5,5,1,1,1),
                                c(10,8,9,5,3),
                                c("A","A","A","B","B"))

names(data)<-c("COUNT","MEASURE","TYPE")

## UNWEIGHTED MEAN BY TYPE
by(data$MEASURE,data$TYPE,mean)

## WEIGHTED MEAN WITHOUT TYPE
weighted.mean(x=data$MEASURE,w=data$COUNT)

## WEIGHTED MEAN BY TYPE - DOESNT WORK
by(data$MEASURE,data$TYPE,weighted.mean(x=data$MEASURE,w=data$COUNT))




-- 
Michael Schumacher
Manager, Data and Analytics
ValueClick
mike.schumacher@gmail.com

	[[alternative HTML version deleted]]

