我正在使用 mtcars 数据库,并且使用 tbl_summary 函数。我想做的是有两个分组依据,首先是变速箱类型,然后是气缸数量,所以我总共有六列分组依据加上整个列,到目前为止我只有能够仅使用一个变量进行分组。
这是我的代码:
mtcars2 <- within(mtcars, {
vs <- factor(vs, labels = c("V", "S"))
am <- factor(am, labels = c("Automatic", "Manual"))
cyl <- ordered(cyl)
gear <- ordered(gear)
carb <- ordered(carb)
})
mtcars2 %>%
tbl_summary(
by = cyl,
type = all_continuous() ~ "continuous2",
statistic = list(all_continuous() ~ c("{mean} ({sd})",
"{min}, {max}",
"{skew}"),
all_categorical() ~ "{n} / {N} ({p}%)"),
digits = all_continuous() ~ 1,
label = list(mpg ~ "Miles/ Gallon", disp ~ "Displacement (cu.in.)", hp ~ "Gross Horsepower", drat …Run Code Online (Sandbox Code Playgroud)