第 6 章 Bookdown中的表格
这是第 6 章的内容, 讲述浮动对象图形的标签与引用. (Xie, 2015a, 2016)
6.1 表格示例1:由数据生成表格
knitr::kable(
head(mtcars[, 1:5], 10), booktabs = TRUE,
caption = 'mtcars数据的前5行.'
)| mpg | cyl | disp | hp | drat | |
|---|---|---|---|---|---|
| Mazda RX4 | 21.0 | 6 | 160.0 | 110 | 3.90 |
| Mazda RX4 Wag | 21.0 | 6 | 160.0 | 110 | 3.90 |
| Datsun 710 | 22.8 | 4 | 108.0 | 93 | 3.85 |
| Hornet 4 Drive | 21.4 | 6 | 258.0 | 110 | 3.08 |
| Hornet Sportabout | 18.7 | 8 | 360.0 | 175 | 3.15 |
| Valiant | 18.1 | 6 | 225.0 | 105 | 2.76 |
| Duster 360 | 14.3 | 8 | 360.0 | 245 | 3.21 |
| Merc 240D | 24.4 | 4 | 146.7 | 62 | 3.69 |
| Merc 230 | 22.8 | 4 | 140.8 | 95 | 3.92 |
| Merc 280 | 19.2 | 6 | 167.6 | 123 | 3.92 |
6.2 表格示例2: 由数据框构造表格
| Category | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| Frequency \(y_i\) | 125 | 18 | 20 | 34 |
| Probability \(p(y_i\mid\pi)\) | \(\frac{1}{2}+\frac{\pi}{4}\) | \(\frac{1}{4}(1-\pi)\) | \(\frac{1}{4}(1-\pi)\) | \(\frac{1}{4}\) |
注意:
- 表格中
%用\\% - 表格中latex命令用
\\代替\
参考文献
Xie, Y. (2015a). Dynamic documents with R and knitr (2nd ed.). Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from http://yihui.name/knitr/
Xie, Y. (2016). Bookdown: Authoring books and technical documents with R markdown. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/bookdown