其中所需的输出应包含每一行的标签,而不仅仅是第一行。
library("expss")
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (lb/1000)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("V-engine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
mtcars %>%
tab_cells(cyl, gear) %>%
tab_prepend_all %>%
tab_cols(total(), vs) %>%
tab_stat_cpct() %>%
tab_pivot()