我一直在使用该xtable包从R矩阵中创建HTML表.当我kable在循环中使用该函数时,它没有输出任何内容.所以我盯着使用这个print功能.问题是,当我使用print函数时,我会在HTML表格中打印出很多"##".有没有办法打印我的kable但在循环中避免每行"##"?
library("xtable", lib.loc="~/R/win-library/3.1")
for(i in 1:3) {
#Must use print because of the loop, but get ## per line
print(kable(head(cars), "html", table.attr='class="flat-table"'))
}
#No neded to use print, no ## printed per line
kable(head(cars), "html", table.attr='class="flat-table"')
Run Code Online (Sandbox Code Playgroud)
And*_*rie 14
你应该告诉chunk按原样使用结果.
通过添加results='asis'到块头来执行此操作.
试试这个:
```{r, results='asis', echo=FALSE}
library(knitr)
library(xtable)
for(i in 1:3) {
#Must use print because of the loop, but get ## per line
print(kable(head(cars), "html", table.attr='class="flat-table"'))
}
```
Run Code Online (Sandbox Code Playgroud)
你应该得到
speed dist
4 2
4 10
7 4
7 22
8 16
9 10
Run Code Online (Sandbox Code Playgroud)