gpt4 book ai didi

r - 如何使用 R 中的 gtsummary 包向表中的标签添加下标?

转载 作者:行者123 更新时间:2023-12-03 23:49:00 25 4
gpt4 key购买 nike

我想在 R 包 gtsummary 中使用 tbl_regression 生成的回归汇总表的变量名称中引入下标。任何人都可以提供有关如何执行此操作的指导吗?用于生成表和结果表的代码如下所示。我希望标签“NO2”显示为“NO2”。

library(tidyverse)
library(gtsummary)

case <- c(0,1,0,0,0,0)
no2 <- c(17, 14, 8, 9, 9, 7)
df <- data.frame(case, no2)

mod_adj <- glm(case~no2,data=df, family="binomial")

regression_table_adj <- mod_adj %>%
tbl_regression(exponentiate = TRUE, label = list(no2~"NO2"))

regression_table_adj

创建于 2020-03-04 由 reprex package (v0.3.0)

A table produced using tbl_regression in the R package gtsummary showing a coefficient name that I want to contain a numeric subscript

最佳答案

这不是我的,但我在这里找到了答案并对其进行了修改。
https://community.rstudio.com/t/subscripts-to-annotate-gt-table/87089
本质上,您会将其转换为 gt对象并破解标签,使其打印为下标。

library(tidyverse)
library(gtsummary)
library(gt)

case <- c(0,1,0,0,0,0)
no2 <- c(17, 14, 8, 9, 9, 7)
df <- data.frame(case, no2)

mod_adj <- glm(case~no2,data=df, family="binomial")

regression_table_adj <- mod_adj %>%
tbl_regression(exponentiate = TRUE, label = list(no2 = "NO@2~")) %>%
as_gt() %>%
text_transform(
locations = cells_body(),
fn = function(x) {
str_replace_all(x,
pattern = "@",
replacement = "<sub>") %>%
str_replace_all("~",
"</sub>") }
)

Image of Table
是的,符号可以轻松替换。我认为最好使用除 '~' 以外的其他东西因为它很容易意味着别的东西。

关于r - 如何使用 R 中的 gtsummary 包向表中的标签添加下标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60534214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com