我有在格式化使用一些表格一些麻烦expss的一个R Markdown。输出是一个pdf文件。knitr选项是:
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
Run Code Online (Sandbox Code Playgroud)
跟随小插图expss(可在此处获得https://cran.r-project.org/web/packages/expss/vignettes/tables-with-labels.html),我编写了以下代码:
sl_expss_long %>% # the tibble
calc_cro_cpct(
cell_vars = list(br, cl, cm, fgm, vd), # rows
col_vars = list(total(), area) # columns
) %>%
set_caption("Table 1")
Run Code Online (Sandbox Code Playgroud)
此代码在 中运行良好R Studio,并生成此表:
Table 1
| | | #Total | Area | |
| | | | Rural | Urban |
| ------------------------------------ | ------------ | ------- | ------ | ------ …Run Code Online (Sandbox Code Playgroud) 这是一个可重现的例子
#install.packages("expss")
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 (1000 lbs)",
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_cols(total(),vs,gear) %>%
tab_cells(gear) %>%
tab_stat_cpct(total_row_position = …Run Code Online (Sandbox Code Playgroud)