我希望能够在 R Markdown 文件中使用代码来描述我的数据表格
xtable(data, type='html')
但是到目前为止我查看的所有包似乎都不与 xtable
在 html
设置中兼容,例如 Hmisc::describe
,reporttools::tableNominal
。
有人有这方面的解决方案吗?
示例: 类似于 Variables Overview with xtable in R 但在 Markdown/html 中工作。
我希望能够在 R Markdown 文件中使用代码来描述我的数据表格
xtable(data, type='html')
但是到目前为止我查看的所有包似乎都不与 xtable
在 html
设置中兼容,例如 Hmisc::describe
,reporttools::tableNominal
。
有人有这方面的解决方案吗?
示例: 类似于 Variables Overview with xtable in R 但在 Markdown/html 中工作。
好的,我找到了一种与R markdown很好配合的选项,那就是使用psych::describe
命令。这样做的优点是最终表格是一个data.frame
对象,可以进一步操作。
使用xtable
library(psych)
library(xtable)
table.desc <- describe(mytable)
print(xtable(table.desc), type="html")
Gmisc
。library(psych)
table.desc <- describe(mytable)
table.prep <- as.matrix(table.desc)
library(Gmisc)
htmlTable(table.prep)
describe
输出的一部分。另外,Gmisc
继承了Hmisc::describe
命令,因此必须在创建统计表后加载AFTER。htmlTable
已经移动到一个单独的包中,不再继承Hmisc。 - Max Gordon> pandoc.table(head(mtcars), split.tables=Inf, style='rmarkdown')
| | mpg | cyl | disp | hp | drat | wt | qsec | vs | am | gear | carb |
|:-----------------------:|:-----:|:-----:|:------:|:----:|:------:|:-----:|:------:|:----:|:----:|:------:|:------:|
| **Mazda RX4** | 21 | 6 | 160 | 110 | 3.9 | 2.62 | 16.46 | 0 | 1 | 4 | 4 |
| **Mazda RX4 Wag** | 21 | 6 | 160 | 110 | 3.9 | 2.875 | 17.02 | 0 | 1 | 4 | 4 |
| **Datsun 710** | 22.8 | 4 | 108 | 93 | 3.85 | 2.32 | 18.61 | 1 | 1 | 4 | 1 |
| **Hornet 4 Drive** | 21.4 | 6 | 258 | 110 | 3.08 | 3.215 | 19.44 | 1 | 0 | 3 | 1 |
| **Hornet Sportabout** | 18.7 | 8 | 360 | 175 | 3.15 | 3.44 | 17.02 | 0 | 0 | 3 | 2 |
| **Valiant** | 18.1 | 6 | 225 | 105 | 2.76 | 3.46 | 20.22 | 1 | 0 | 3 | 1 |
pandoc
导出,所以还没有尝试过。 - Joanne Demmlerpander
:) 只需进行小小的添加即可提高软件包的可用性:可以使用 panderOptions
设置所有表格的 style
,以及是否需要拆分表格,然后只需在任何 R 对象上调用 pander
即可。 - daroczig
R2HTML
吗? - ThomasR2HTML::HTML(data, file=stdout())
并保持所有内容自包含。 - Thomas