r - 如何保存expss包的输出?
问题描述
我使用 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%)?)
解决方案
要将表格另存为 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 | | |
到目前为止,没有选项可以将统计信息放在同一单元格的括号中。
推荐阅读
- angular-cli - 有没有办法在角度 json 配置中为 ng serve 指定后备端口?
- javascript - API 的响应未定义
- google-cloud-platform - 如何使用 Google Healthcare Consent API 检查基于 userId 和 dataId 的访问权限?
- java - 将扁平化的 CSV 转换为嵌套的 JSON
- perl - CPAN 中的 Perl JDBC 模块使用问题
- swift - 在 Swift PlaygroundBook 中访问资源
- javascript - 哪个是与 d3 一起使用的用户友好的 csv 结构?
- javascript - 根据在指定行中选择的内容将数据单元格添加到工作表
- c++ - Cmake无法复制dll
- php - 比较 2 个数组并获取 PHP 中最接近 0 的值