Programmatically creating Markdown tables in R with KnitR

前端 未结 8 1729
梦谈多话
梦谈多话 2020-11-29 15:25

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

8条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 15:39

    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|
    

    UPDATED: if you get raw markdown in a document try setup results = "asis" chunk option.

提交回复
热议问题