0

If one has a data set that looks as follows:

data <- data.frame()
data$gender <- c(F,F,F,M,F)
data$province <- c(G,N,K,L,K)
data$volume <- c(500,750,1250,NA,300)
data$weight <- c(1.36,0.67,5.22,1.66,1.14)

How do I apply these weights to the data set? Is it enough to just multiply the sample weights with the numerical variables or do the categorical variables also have to be weighted?

double-beep
  • 5,031
  • 17
  • 33
  • 41
ishido
  • 4,065
  • 9
  • 32
  • 42
  • you can try the `barplot()` function. See the help for more infos, using `?barplot()` – Roman Oct 25 '16 at 11:05
  • my issue isn't the creation of the plot, but how to apply the weights to the data set before actual plotting – ishido Oct 25 '16 at 11:21

1 Answers1

2

The questionr and survey packages handle weighting. Here's an example:

library("questionr")
table <- wtd.table(data$gender, weights = data$weight)
barplot(as.matrix(table))
Rupert
  • 199
  • 10