Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (5.3k points)

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?

1 Answer

0 votes
by

To create markdown tables in R, you can use the kable function from the knitr package as follows:

library(knitr)

> kable(head(iris[,2:5]), format = "markdown")

Output:

| Sepal.Width| Petal.Length| Petal.Width|Species |

|-----------:|------------:|-----------:|:-------|

|         3.5|          1.4|         0.2|setosa  |

|         3.0|          1.4|         0.2|setosa  |

|         3.2|          1.3|         0.2|setosa  |

|         3.1|          1.5|         0.2|setosa  |

|         3.6|          1.4|         0.2|setosa  |

|         3.9|          1.7|         0.4|setosa  |

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...