GT摘要 - 如何仅在桌子的某些行上删除N'

发布于 2025-02-12 14:40:07 字数 1294 浏览 3 评论 0原文

我希望进行测试,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()

我的第二个问题是如何使丢失的数据取决于变量而不是整体上?因为如果我将丢失=“如果”放置,那么对于我的某些数据而言,这是无关紧要的,因为只是无法回答这些问题的人。

非常感谢您的回答,祝您有美好的一天!

I would like that for Test, Test2 ... Test7, that the N does not appear in the table.
But I can't do either select or filter and I can't find any solution to make it disappear but stay on the other variables of the table.
This a part of my code:

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()

My second question is how do you make the missing data dependent on the variables and not on the whole? because if i put missing = "ifany", for some of my data it's irrelevant because that just people who couldn't answer theses questions.

Thank you a lot for your answer, have a great day!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我三岁 2025-02-19 14:40:07

我不确定如果没有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
特征n = 200
年龄47(38,57)
未知11
患者死于112(56%)
肿瘤反应
肿瘤反应

I am not sure I understand what you're trying to get achieve without the N for the test variables. But i've included an example with what you may be after.

You can use the remove_row_type() function to remove the missing rows for selected variables.

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
CharacteristicN = 200
Age47 (38, 57)
Unknown11
Patient Died112 (56%)
Tumor Response
Tumor Response

Created on 2022-07-01 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文