tbl_summary()不显示r中的是/否级别

发布于 2025-02-13 13:22:21 字数 769 浏览 4 评论 0原文

在下面的数据框架中,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软件包并未显示出因子级别摘要表但不幸的是我无法解决这个问题。我很感谢任何提示或帮助这一点?

in data frame below g variable has two levels, however tbl_summary() is not showing the its levels.

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

enter image description here

I tried following R gtsummary package doesnt show the factor levels in the summary table but unfortunately I could not solve this issue. I would appreciate any hint or help with this?

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

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

发布评论

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

评论(1

凌乱心跳 2025-02-20 13:22:21

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

对于特定列:

library(gtsummary)

df |> tbl_summary(by = output, type = list(g ~ "categorical"))

所有“是”/“否”列:

library(gtsummary)
library(stringr)

names_of_yes_no_columns <- names(Filter(function(x) all(str_detect(x, "Yes|No")), df))

df |> tbl_summary(by = output, type = list(names_of_yes_no_columns ~ "categorical"))

所有二分法变量(@daniel D. Sjoberg):

library(gtsummary)

df |> tbl_summary(by = output, type = all_dichotomous() ~ "categorical")

输出:

“在此处输入图像说明”

You could use type in tbl_summary to specify how to display it.

For specific columns:

library(gtsummary)

df |> tbl_summary(by = output, type = list(g ~ "categorical"))

All "Yes"/"No" columns:

library(gtsummary)
library(stringr)

names_of_yes_no_columns <- names(Filter(function(x) all(str_detect(x, "Yes|No")), df))

df |> tbl_summary(by = output, type = list(names_of_yes_no_columns ~ "categorical"))

All dichotomous variables (@Daniel D. Sjoberg):

library(gtsummary)

df |> tbl_summary(by = output, type = all_dichotomous() ~ "categorical")

Output:

enter image description here

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