December 2017
Beginner to intermediate
470 pages
12h 29m
English
In informal reports, you may just print out a matrix or data frame rather than creating a formal table. If you need to, there are multiple ways to make tables with R Markdown that may look a bit nicer. We show how to use kable from the knitr package, as it's the simplest one. If you need more control, you may look at the xtable package, which gives you complete control. You need to be sure to use results = "asis" in the code chunk.
If we use the following input:
```{r r-markdown-label, results = "asis"}
library(knitr)
x <- rnorm(100)
y <- 2 * x + rnorm(100)
coeficients <- summary(lm(y ~ x))$coef
kable(coeficients, digits = 2)
```
We get the following output:
| Estimate | Std. error | t value | Pr(>|t|) | |
| (Intercept) | 0.02 | 0.10 | 0.21 | 0.83 ... |