calculate weighted s.d in r

100 views Asked by At

I want to calculate in r weighted mean and weighted standard deviation (the weights are sample weights, for a survey sample. It is suppose to show how many units in the population represent each unit in the sample).

I tried to calculate this by two ways and got the same answers for the means, but different answers for the s.d.

Is one of the ways correct?

the first way-

a<-c(1,2,3)
b_gender<-c('men','men','women')
c_weight<-c(1,1,2)
table1<-tableby(gender~a, weights=c_wei)

another way-

a<-c(1,2,3)
gender<-c('men','men','women')
c_weight<-c(1,1,2)
w.mean(a, c_wei)
   w.ds(a, c_wei)
0

There are 0 answers