我使用expss包来生成mtcar数据的汇总表。
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()我得到这样的输出:

现在,我想将输出保存为html、pdf或jpeg文件。不幸的是,在循环之前或循环内执行save.image都不能正常工作。对此一定有一个简单的解决方案?我也试图以某种方式从查看器导出,但也失败了。
此外,是否有可能在一行中显示每个不同发动机的系数(即气缸)的箱数及其总体比例(例如,n箱(xy%) ?)
发布于 2021-02-04 07:29:00
要将表格保存为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 | | |到目前为止,还没有将统计数据放入同一单元格的括号中的选项。
https://stackoverflow.com/questions/65923353
复制相似问题