如何在针织衫中打印表格 [英] how do you print table in knitr
本文介绍了如何在针织衫中打印表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试用knitr使用xtable
以表格格式打印数据框:
I am trying to us knitr to print data frame in table format using xtable
:
```{r xtable,fig.width=10, fig.height=8, message=FALSE, results = 'asis', echo=FALSE, warning=FALSE, fig.cap='long caption', fig.scap='short',tidy=FALSE}
print(xtable(d),format="markdown")
```
这是数据帧d
:
d <- structure(list(Hostname = structure(c(8L, 8L, 9L, 5L, 6L, 7L,
1L, 2L, 3L, 4L), .Label = c("db01", "db02", "farm01", "farm02",
"tom01", "tom02", "tom03", "web01", "web03"), class = "factor"),
Date = structure(c(6L, 10L, 5L, 3L, 2L, 1L, 8L, 9L, 7L, 4L
), .Label = c("10/5/2015 1:15", "10/5/2015 1:30", "10/5/2015 2:15",
"10/5/2015 4:30", "10/5/2015 8:30", "10/5/2015 8:45", "10/6/2015 8:15",
"10/6/2015 8:30", "9/11/2015 5:00", "9/11/2015 6:00"), class = "factor"),
Cpubusy = c(31L, 20L, 30L, 20L, 18L, 20L, 41L, 21L, 29L,
24L), UsedPercentMemory = c(99L, 98L, 95L, 99L, 99L, 99L,
99L, 98L, 63L, 99L)), .Names = c("Hostname", "Date", "Cpubusy",
"UsedPercentMemory"), class = "data.frame", row.names = c(NA,
-10L))
有什么想法我在这里想念的吗?
Any ideas what I am missing here?
推荐答案
尝试使用knitr
中的kable
.它将很好地格式化表格.
Try kable
from knitr
. It will format the table nicely.
如果您想使用xtable
,请尝试:
If you would like to use xtable
try:
print(xtable(d), type="latex", comment=FALSE)
这篇关于如何在针织衫中打印表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文