0

I have a weighting variable that I'd like to apply to my dataset so that I have weighted totals. In SPSS, this is straightforward enough. However, in R, I've been multiplying the variable by the weight variable to create a new variable as shown in the following example:

https://stats.stackexchange.com/questions/210697/weighting-variable-based-on-another-variable

Is there a more sophisticated way of applying weights in R?

Thanks.

  • Vector multiplication is a single line of code, if I understand correctly that is what you meant, I don't see how it is unsophisticated to be honest. you don't need packages for that, simply multiply the W vector by the acres vector and then sum them. If you want i can write the code down there for you. – dvd280 Mar 28 '20 at 20:54
  • Great, thanks. Perhaps I'm over thinking it then. I was planning on doing something like this in R: income_2018$weighted_sex <- income_2018$sex*income2018$indivwght – John Wildman Mar 29 '20 at 10:38

1 Answers1

1

If you need to work with a weighted dataset and define a complex survey sample, you can use the survey package : https://cran.r-project.org/web/packages/survey/survey.pdf. You can therefore use all sorts of summary statistics once you have defined the weights to be applied. However, I would advise this for complex weighted analysis.

Otherwise, there are several other packages dealing with weights such as questionr for instance.

It all depends on if you have to do a simple weighted sum or go on to do other types of analysis that require using more sophisticated methods.

Raphaele Adjerad
  • 1,117
  • 6
  • 12