subset survey and use in gtsummary

Hi people! I'm trying to compare two groups in my survey object using the gtsummary package, but I'm encountering an error that I'm not sure how to resolve. Below is what I'm attempting to do. The data is from the PNSIBGE package. The error is: "Error: 'tbl_summary'/'tbl_svysummary' object must have a by= value with exactly two levels". Does anyone know how to solve this?

install.packages("PNSIBGE")
library(PNSIBGE)
library(tidyverse) 
library(gtsummary)

pns <- get_pns(year = 2019, labels = T) 
pns.2 <- subset(pns, C009 %in% c("Branca", "Preta"))
pns.2$variables$C009 <- droplevels(pns.2$variables$C009) 

pns.2 %>% tbl_svysummary(by = C009, include = c(C006)) %>% 
  add_difference()

Thank you very much

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.