简体   繁体   English

R describe和R Markdown

[英]R describe and R Markdown

I'd like to describe my data table in a R Markdown file using 我想使用R Markdown文件describe我的数据表

xtable(data, type='html')

But none of the packages I looked so far seem to be compatible with xtable in html setting, fi Hmisc::describe , reporttools::tableNominal . 但是到目前为止,我看过的所有软件包似乎都不与html设置中的xtable兼容, xtable Hmisc::describereporttools::tableNominal

Does anyone have a solution for this? 有人对此有解决方案吗?

Example: Something like Variables Overview with xtable in R but working in Markdown/html. 示例:类似于R中带有xtable的Variables Overview,但可以在Markdown / html中使用。

try pander package. 尝试pander包。 specifically pandoc.table function from that package 特别是该包中的pandoc.table函数

> 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    |

That markdown table should render as follows 该降价表应呈现如下

在此处输入图片说明

Ok, I've found one option that does work well with R markdown and that is using the psych::describe command. 好的,我找到了一个可以很好地与R markdown一起使用的选项,并且使用psych::describe命令。 This has the advantage that the final table is a data.frame object that can then be further manipulated. 这样做的好处是,最终表是一个data.frame对象,然后可以对其进行进一步操作。

with xtable xtable

library(psych)
library(xtable)
table.desc <- describe(mytable)
print(xtable(table.desc), type="html")

or using Gmisc 或使用Gmisc

library(psych)
table.desc <- describe(mytable)
table.prep <- as.matrix(table.desc)
library(Gmisc)
htmlTable(table.prep)

Please note that in this example you do want to include the rownames, as they are part of the describe output. 请注意,在此示例中,您确实要包括行名,因为它们是describe输出的一部分。 Also Gmisc inherits the Hmisc::describe command and has thus to be loaded AFTER creating the stats table. 另外, Gmisc继承了Hmisc::describe命令,因此必须在创建stats表之后加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM