r语言 - Gt 摘要 - 如何仅在表的某些行上删除 N 并保留另一行?



我想为Test, Test2…Test7,表示N没有出现在表中。但我既不能选择也不能过滤,我找不到让它消失的方法,只能保留表的其他变量。这是我代码的一部分:

base %>%
tbl_summary(include = all_of(var_interet),
statistic =list(
all_categorical() ~ "{n} ({p}%)",
Test ~ " ", 
Test2 ~" ", 
Test3 ~ " ", 
Test4 ~ " ", 
Test5 ~ " ", 
Test6 ~ " ", 
Test7~ " "),
digits = list(
all_categorical() ~ c(0, 1)
), 
type = list(
Q1_oui_systematique ~ "dichotomous", 
Q1_non_temps ~ "dichotomous", 
Q1_non_outils ~ "dichotomous", 
Q1_non_aise ~ "dichotomous", 
Q1_non_necessaire ~ "dichotomous", 
Q1_non_autre ~ "dichotomous"),   
sort = c(ID_type_centre, ID_repondant,presence_tiers1, Q1_oui_systematique, Q2_oui_mod_decouverte, Q4) ~ "frequency",
missing = "no") %>%
bold_labels() %>% 
italicize_levels()%>%
modify_spanning_header(all_stat_cols() ~ "**Ps**")%>%
add_n()

我的第二个问题是如何使缺失的数据依赖于变量而不是整体?因为如果我加上missing = "ifany",对于我的一些数据来说,这是不相关的,因为这只是那些无法回答这些问题的人。

谢谢你的回答,祝你有美好的一天!

我不确定我是否理解您在没有测试变量N的情况下试图实现的目标。但是我已经包含了一个你可能需要的例子。

您可以使用remove_row_type()函数删除所选变量的缺失行。

library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.6.1'
trial %>%
select(age,
death,
test1 = response, 
test2 = response) %>%
tbl_summary(
statistic = 
list(death ~ "{n} ({p}%)",
c(test1, test2) ~ "") # show no statistics for the test variables

) %>%
# remove the missing row for the test variables
remove_row_type(variables = c(test1, test2), type = "missing") %>%
as_kable() # convert to kable to display on SO
特征strong>n = 20047 (38,57)112

最新更新