2

我的问题与这里的问题有点相似。

我有以下代码:

library(gtsummary)
basicvars <- names(isoq) %in% c("homeless_nonself", "test_result")
basictable <- isoq[basicvars]
    # summarize the data
table1 <- tbl_summary(basictable, missing = "always",                              
                      missing_text = "(Missing)",
                      percent = "cell",
                      type = all_dichotomous() ~"categorical"
) %>%
  bold_labels()

############Selecting the order of variables 
basiccompletetable <- basictable %>% select(test_result,homeless_nonself)
mutate(test_result = factor(test_result) %>% fct_explicit_na()) %>%
  
table3 <- tbl_summary(basiccompletetable, #missing = "always", missing_text = "(Missing)",
                      percent = "cell",
                      label = list( 
                        test_result ~ "COVID-19 Test Result",
                        homeless_nonself ~ "Homeless",
                        
                      ),
                      sort = list(
                        test_result ~ "frequency",
                        homeless_nonself ~ "frequency",
                        ),
                      type = list(all_character() ~ "categorical")
) %>%
  modify_spanning_header(starts_with("stat_") ~ "**All**") %>%
  modify_header(label = "**Variable**") %>%  # update the column header
  #add_n() %>%
  bold_labels() %>%
  as_gt() %>%
  gt::tab_source_note(gt::md("*This data is simulated*"))
table3

它吐出输出(不是完整的输出)

在此处输入图像描述

我试图显示缺失值的百分比。首先尝试使用 test_result。将这行代码mutate(test_result = factor(test_result) %>% fct_explicit_na()) %>%用于前面问题中的建议。但是,我看到与输出相同的表,并且变量 test_result 的缺失值没有百分比。

有什么建议为什么这不起作用?谢谢

4

0 回答 0