【问题标题】:tbl_summary() not showing YES/NO levels in Rtbl_summary() 未在 R 中显示 YES/NO 级别
【发布时间】:2022-07-06 23:57:19
【问题描述】:

在 g 变量下面的数据框中有两个级别,但是 tbl_summary() 没有显示其级别。

data.frame(a=c(0,1,2),
           
           b=c(0,1,2),
           
           f=c("m", "f", "m"),
           
           g = c("Yes", "No", "Yes"),
           
           output = c(0,1,0)) %>%
  
  tbl_summary(by=output)

  a b f   g output
1 0 0 m Yes      0
2 1 1 f  No      1
3 2 2 m Yes      0

我尝试关注R gtsummary package doesnt show the factor levels in the summary table,但不幸的是我无法解决这个问题。如果有任何提示或帮助,我将不胜感激?

【问题讨论】:

  • 这不是问题,这是一个特性——g 是一个二分变量; tbl_summary 注意到并正确显示了“是”的频率和比例 - 显示“否”值是没有意义的,因为它可以通过从“是”中减去总数来得出。
  • 是的,理性的。但我相信在视觉上将它们也显示出来会更有趣和可读。那么有什么方法可以强制 gtsummary 显示两个级别。特别是因为如果 2 表示是或否并不明显。它甚至没有显示级别是或否。
  • @harre,不幸的是,正如我在帖子中提到的那样。

标签: r dplyr categorical-data gtsummary


【解决方案1】:

您可以在tbl_summary 中使用type 来指定如何显示它:

data.frame(a = c(0,1,2),
           b = c(0,1,2),
           f = c("m", "f", "m"),
           g = c("Yes", "No", "Yes"),
           output = c(0, 1, 0)) %>%
  tbl_summary(by = output, type = list(g ~ "categorical"))

更新:意识到这(几乎)与链接帖子中的答案相同:R gtsummary package doesnt show the factor levels in the summary table。 标记为重复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-02
    • 2020-06-23
    • 2017-12-06
    • 1970-01-01
    • 2016-08-11
    • 2020-02-05
    • 2012-04-19
    • 2015-10-07
    相关资源
    最近更新 更多