使用KnitR以编程方式在R中创建Markdown表 [英] Programmatically creating Markdown tables in R with KnitR
问题描述
我才刚刚开始了解KnitR以及在生成R文档和报告中使用Markdown.对于我每天与工作有关的许多日常报告来说,这看起来是完美的.但是,我没有看到的一件事是使用Markdown格式(类似于xtable
,但使用Markdown而不是LaTeX或HTML)打印数据框和表格的一种简便方法.我知道我可以嵌入xtable的HTML输出,但是我想知道是否有任何基于Markdown的解决方案?
I am just starting to learn about KnitR and the use of Markdown in generating R documents and reports. This looks to be perfect for a lot of the day to day reporting that I have to do with my job. However, one thing that I'm not seeing is an easy way to print data frames and tables using Markdown formatting (sort of like xtable
, but with Markdown instead of LaTeX or HTML). I know that I can just embed the HTML output from xtable, but I was wondering if there were any Markdown-based solutions?
推荐答案
现在knitr
(自1.3版开始)软件包包括用于创建表的kable
函数:
Now knitr
(since version 1.3) package include the kable
function for a creation tables:
> library(knitr)
> kable(head(iris[,1:3]), format = "markdown")
| Sepal.Length| Sepal.Width| Petal.Length|
|-------------:|------------:|-------------:|
| 5,1| 3,5| 1,4|
| 4,9| 3,0| 1,4|
| 4,7| 3,2| 1,3|
| 4,6| 3,1| 1,5|
| 5,0| 3,6| 1,4|
| 5,4| 3,9| 1,7|
已更新:如果您在文档中收到原始的降价优惠,请尝试设置results = "asis"
块选项.
UPDATED: if you get raw markdown in a document try setup results = "asis"
chunk option.
这篇关于使用KnitR以编程方式在R中创建Markdown表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!