Trying to get weighted mean for a couple of categories want to use by(df$A,df$B,function(x) weighted.mean(x,df$C)) This doesn't work of course. Is there a way to do this using by() and weighted.mean()
df= data.frame(A=c(1,4,56,4,3),B=c('hi','gb','hi','gb','yo'),C=c(5,2,4,1,3))
by(df$A,df$B,function(x) weighted.mean(x,df$C)) #doesn't work
I have a bunch of work arounds but it would so simple if I could just use that format.