Advanced Rmarkdown
kable Tables I
The
kable
functionality in
Rmarkdown
enables us to generate appealing L
A
T
E
X
-styled tables directly via R coding:
library(kableExtra)
tabout <- as.data.frame(matrix(c(1:20), nrow = 5))
rownames(tabout) <- c("R1", "R2", "R3", "R4", "R5")
colnames(tabout) <- c("C1", "C2", "C3", "C4")
kab <- kable(tabout, booktabs = TRUE, caption = paste("\\textbf{",
"Short Description", " -} ", "Long Description",
sep = ""), caption.short = "Short Description",
escape = FALSE, format = "latex")
kab <- add_header_above(kable_input = kab, header = c(
` `
= 1,
`
First two columns
`
= 2,
`
Last two columns
`
= 2),
bold = TRUE, align = "c")
kab <- kable_styling(kab, latex_options = c("hold_position"))
print(kab)
Code chunks which generate kable tables need an additional argument:
results = 'asis'.
Aarhus University Excursions into Biostatistics 21 / 28