79456754

Date: 2025-02-21 08:45:34
Score: 1
Natty:
Report link

For dichtomous variables, the tbl_summary() function provides the option to display only one category by using the type argument. The following code provides the solution. It correctly considers the total N.

library(gtsummary)
d<-tibble::tribble(
      ~Gender, ~Treatment,      
      "Male", "A",
      "Male", "B", 
      "Female", "A",
      "Male", "C",
      "Female", "B",
      "Female", "C")

d %>% tbl_summary(
  by    = Treatment, 
  # declare Gender as dichotomous variable
  type  = list(Gender ~ 'dichotomous'), 
  # set the value to show
  value = list(Gender ~ 'Female'), 
  # by default as characteristic still "Gender" is shown, change to "Female"
  label = list(Gender ~ 'Female'))

The output:

tbl_summary() output

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Statistican