I have a probably very simple question, I hope you will be able to help me with. I have to compute weighted averages for proportion liberal in each american state. I have computed the 'raw' proportion liberal by this command:
liberal.state<-aggregate(liberal, by=list(state), mean ,na.rm=TRUE)
#liberal=binary variable
This works fine!
I have also a function of sample size pr. state:
sample.state<-aggregate(rid, list(state=state), length)
#rid=id for respondent
This works fine as well!
I want to weight the weighted averages of proportion liberal in each state. I use this formula:
N <- sample.state
p <- liberal.state
w.avg <-sum(N*p)/sum(N)
But I keep getting this error message:
Error in FUN(X[[1L]], ...) :
only defined on a data frame with all numeric variables
In addition: Warning message:
In Ops.factor(left, right) : ‘*’ not meaningful for factors
I hope one of you will be able to help me! Thank you in advance!
Best Sofie