I withdraw this question, I was able to accomplish this by creating a new
function.
Now if only I could get the by output into a dataframe...
Mike
On Wed, Feb 23, 2011 at 2:25 PM, Mike Schumacher
<mike.schumacher@gmail.com>wrote:
> 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
>
>
>
>
--
Michael Schumacher
mike.schumacher@gmail.com
818-851-8638
[[alternative HTML version deleted]]