列印表
有幾個包允許以 HTML 或 LaTeX 表的形式輸出資料結構。它們的靈活性大多不同。
在這裡我使用包:
- knitr
- xtable
- 拉皮條
對於 HTML 文件
author: "Martin Schmelzer"
date: "29 Juli 2016"
output: html_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
`library(knitr)`
`library(xtable)`
`library(pander)`
df <- mtcars[1:4,1:4]
```
# Print tables using `kable`
```{r, 'kable'}
`kable(df)`
```
# Print tables using `xtable`
```{r, 'xtable', results='asis'}
print(`xtable(df)`, type="html")
```
# Print tables using `pander`
```{r, 'pander'}
`pander(df)`
```
對於 PDF 文件
author: "Martin Schmelzer"
date: "29 Juli 2016"
output: pdf_document
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
`library(knitr)`
`library(xtable)`
`library(pander)`
df <- mtcars[1:4,1:4]
```
# Print tables using `kable`
```{r, 'kable'}
`kable(df)`
```
# Print tables using `xtable`
```{r, 'xtable', results='asis'}
print(xtable(df, caption="My Table"))
```
# Print tables using `pander`
```{r, 'pander'}
`pander(df)`
```
如何在每張表之前停止 xtable 列印註釋?
options(xtable.comment = FALSE)