Closed kkerin closed 1 year ago
It looks like you need fct_na_level_to_value()
:
library(gtsummary)
#> #BlackLivesMatter
gender <- forcats::fct_na_level_to_value(sample(c("Male", "Female", NA), 100, replace = TRUE))
df <- data.frame(gender)
df |>
tbl_summary(missing_text = "Missing") |>
as_kable()
Characteristic | N = 100 |
---|---|
gender | |
Female | 29 (48%) |
Male | 32 (52%) |
Missing | 39 |
Created on 2023-10-31 with reprex v2.0.2
Using "fct_na_value_to_level" can't missing value, when gtsummary reporting categorical variables with missing from the total not the available total. But "fct__explicit_na" worked well:
like such scene below:
Then I will get:
but if i use "gender = forcats::fct_na_value_to_level(gender)", I will get