要将表格另存为 html,您可以htmlTable
在序列末尾添加函数,然后保存 HTML 代码:
library(expss)
data(mtcars)
mtcars %>%
tab_cells(cyl) %>%
tab_cols(total(), vs) %>%
tab_rows(am) %>%
tab_stat_cpct(total_row_position = "above",
total_label = c("number of cases", "row %"),
total_statistic = c("u_cases", "u_rpct")) %>%
tab_pivot() %>%
htmlTable() %>%
writeLines("my_table.html")
您可以使用以下代码在一行中生成案例和表格百分比:
library(expss)
data(mtcars)
mtcars %>%
tab_cells(cyl) %>%
tab_cols(total(), vs) %>%
tab_rows(am) %>%
tab_stat_cases(total_row_position = "none") %>%
tab_stat_tpct(total_row_position = "none") %>%
tab_pivot(stat_position = "inside_columns")
# | | | | | #Total | | vs | | | |
# | | | | | | | 0 | | 1 | |
# | -- | -- | --- | -- | ------ | ----- | -- | ----- | -- | ----- |
# | am | 0 | cyl | 4 | 3 | 15.79 | | | 3 | 15.79 |
# | | | | 6 | 4 | 21.05 | | | 4 | 21.05 |
# | | | | 8 | 12 | 63.16 | 12 | 63.16 | | |
# | | 1 | cyl | 4 | 8 | 61.54 | 1 | 7.69 | 7 | 53.85 |
# | | | | 6 | 3 | 23.08 | 3 | 23.08 | | |
# | | | | 8 | 2 | 15.38 | 2 | 15.38 | | |
到目前为止,没有选项可以将统计信息放在同一单元格的括号中。