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.schumac...@gmail.com [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org 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.