Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Tables

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content