gtsummary::tbl_summary 提供了不同风格的表格

问题描述 投票:0回答:1

我在 R4.4 上使用 gtsummary::tbl_summary。我收到了一个使用以下 df 的表格:

structure(list(Treatment = c("Verum", "Verum", "SoC", "SoC",  "Verum"), PTN = c(7.91749000549316, 7.60503005981445, 8.45341014862061,  8.48719024658203, 7.39421987533569), HGF = c(13.0622499583508,  12.6070907710339, 12.3543298838879, 12.2434056399609, 13.6388056872632 ), FGF_21 = c(5.53692184768091, 5.28081165633569, 5.68246208510767,  5.6471217759646, 4.85877167067895), PVALB = c(8.4968900680542,  4.57206010818481, 7.59231996536255, 8.43292999267578, 6.51680994033813 )), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame" ))

我收到的wrong table有以下几个方面。

我想收到每种不同蛋白质的每种治疗的中位数,就像这样desired

到目前为止我一直在使用以下内容:

df %>% tbl_summary(by = "Treatment") %>% add_p() %>%  sort_p() %>% modify_header(label ~ "**Treatment**") %>%  modify_spanning_header(c("stat_1", "stat_2") ~ "**Treatment Received at day = 8**") %>% bold_labels()

感谢您的帮助 问候 安德里亚

r median gtsummary
1个回答
0
投票

您必须强制

tbl_summary
将变量视为连续变量,否则,它会将它们视为分类变量,因为不同的值太少了。

df %>% tbl_summary(by = Treatment,
                   type=list(everything()~"continuous")) %>% 
  add_p() %>%  
  sort_p() %>% 
  modify_header(label ~ "**Treatment**") %>%  
  modify_spanning_header(c("stat_1", "stat_2") ~ "**Treatment Received at day = 8**") %>% 
  bold_labels()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.