I'm working on a dataset that includes a post-stratification weight, and I am looking for a way to get more info about specific variables after they have been weighted, but I am struggling.
Here's a sample dataframe:
a <- c(1, 3, 2, 1, 2, 2, 3, 3, 1, 3, NA, NA)
wght <- c(0.8, 0.9, 1.2, 1.5, 0.5, 1, 0.7, 0.9, 0.8, 1.1, 1, 0.8)
df <- data.frame(a, wght)
Column a contains the coded responses to a question (say agree
/neutral
/disagree
), and wght
contains the weight. I found a way to display the weighted number of observations:
library(magrittr)
df %>% dplyr::count(a, wt=wght)
I would now like to get the info on this distribution that I could get with freq
from the descr
package (especially percentage and valid percentage). I tried various things, such as the following, but it produces a strange frequency table.
dfwt <- df %>% count(a, wt=wght)
freq(dfwt$a)