我在expss
使用R Markdown
. 输出是一个pdf文件。knitr
选项是:
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
按照上的小插图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")
此代码在 中运行良好R Studio
,并生成此表:
Table 1
| | | #Total | Area | |
| | | | Rural | Urban |
| ------------------------------------ | ------------ | ------- | ------ | ------ |
| Birth registration | FALSE | 64.4 | 61.6 | 70.9 |
| | TRUE | 35.6 | 38.4 | 29.1 |
| | #Total cases | 8207.0 | 5732.0 | 2475.0 |
| Child labour | FALSE | 50.5 | 47.0 | 64.2 |
| | TRUE | 49.5 | 53.0 | 35.8 |
| | #Total cases | 5136.0 | 4085.0 | 1051.0 |
| Child marriage | FALSE | 98.8 | 98.6 | 99.2 |
| | TRUE | 1.2 | 1.4 | 0.8 |
| | #Total cases | 12158.0 | 7827.0 | 4331.0 |
| Female genitale mutilation / cutting | FALSE | 8.2 | 7.6 | 9.3 |
| | TRUE | 91.8 | 92.4 | 90.7 |
| | #Total cases | 9203.0 | 6144.0 | 3059.0 |
| Violent child discipline | FALSE | 9.9 | 10.4 | 8.9 |
| | TRUE | 90.1 | 89.6 | 91.1 |
| | #Total cases | 11547.0 | 7818.0 | 3729.0 |
同样,它适用于R Studio
以下代码:
sl_expss_long %>%
tab_cells(br, cl, cm, fgm, vd) %>%
tab_cols(total(), area) %>%
tab_stat_cpct() %>%
tab_pivot() %>%
set_caption("Table with summary statistics and significance marks.")
但是,当我将代码放入我的中时R Markdown
,我得到以下结果:
Table with summary statistics
National
Area
Rural
Urban
Birth registration
FALSE
64.4
61.6
70.9
TRUE
35.6
38.4
29.1
#Total cases
8207
etc.
我的表只有一列宽和三页长。
我暂时用pander
,kable
和kableExtra
>
sl_expss_long %>%
tab_cells(br, cl, cm, fgm, vd) %>%
tab_cols(total(label = " National| |"), area) %>%
tab_stat_cpct() %>%
tab_pivot() %>%
set_caption("Table with summary statistics") %>%
split_table_to_df() %>%
kable(caption = "Table with summary statistics") %>%
kable_styling(bootstrap_options = c("striped"),
latex_options = "hold_position") %>%
row_spec(1:2, bold = TRUE)
并得到这个结果:
如您所见,表格 from 在表格R Markdown
的开头添加了一行,并且“区域”一词应该位于“农村”和“城市”的顶部。这是基于我对小插图的理解是expss
在 a中使用R Markdown
会产生我们可以在小插图中看到的表格。
对我可能遗漏的内容有任何帮助吗?
提前谢谢了
马诺洛