默认情况下,变量“Var2”已设置为分类变量,而有时需要平均值(sd)。所以我对如何修改它很感兴趣。
data_table_1 =
data %>%
dplyr::select(group, var1, var2)
data_table_1 %>%
tbl_summary(by = group, missing = "no",
statistic = list(all_continuous() ~ "{mean} ± {sd}",
all_categorical() ~ "{n} ({p}%)"),
digits = list(all_continuous() ~ c(2, 2))) %>%
add_p(test = list(all_continuous() ~ "pttest2", all_categorical() ~ "pttest2"),
pvalue_fun = function(x) sprintf(x, fmt='%#.3f'))