我试图用两个类别变量来总结一个连续变量,如下所示。我无法正确执行此操作。我想知道是否有一种方法可以通过gradlew clean shadowJar publish
包来实现。谢谢
gtsummary
答案 0 :(得分:1)
我在这里发布了对此问题的答案:https://community.rstudio.com/t/summarizing-a-continuous-variables-by-two-categorical-variables-with-the-gtsummary-package/81937/2
tbl_summary()
函数在编写时并未考虑到这种类型的输出....但是您可以使用tbl_summary()
和tbl_stack()
来实现。
library(gtsummary)
#> #Uighur
library(tidyverse)
trial %>%
# keep the continuous var and the two categorical variables
select(trt, age, grade) %>%
group_nest(grade) %>%
mutate(
tbl = map2(
grade, data,
~tbl_summary(.y, by = trt,
label = list(age = paste("Age: Grade", .x)), missing = "no")
)
) %>%
pull(tbl) %>%
tbl_stack() %>%
as_tibble()
#> # A tibble: 3 x 3
#> `**Characteristic**` `**Drug A**, N = 35` `**Drug B**, N = 33`
#> <chr> <chr> <chr>
#> 1 Age: Grade I 46 (36, 60) 48 (42, 55)
#> 2 Age: Grade II 44 (31, 54) 50 (43, 57)
#> 3 Age: Grade III 52 (42, 60) 45 (36, 52)
由reprex package(v0.3.0)于2020-09-24创建