将stargazer或xtable表格插入knitr文档

7
> dput(head(t))
structure(list(Team = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "Union", class = "factor"), 
    Date = structure(c(1L, 1L, 1L, 2L, 2L, 2L), .Label = c("2012-01-06", 
    "2012-02-06", "2012-03-06", "2012-04-06", "2012-05-06", "2012-07-06", 
    "2012-09-06", "2012-10-06", "2012-11-06", "2012-12-06"), class = "factor"), 
    STime = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = "07:03", class = "factor"), 
    ETime = structure(c(6L, 7L, 8L, 5L, 5L, 1L), .Label = c("01:13", 
    "03:13", "06:13", "09:13", "10:13", "11:13", "12:13", "13:13", 
    "15:13", "16:13", "18:13"), class = "factor")), .Names = c("Team", 
"Date", "STime", "ETime"), row.names = c(NA, 6L), class = "data.frame")

我希望能够使用stargazer或xtable将数据框架t转换成表格格式并在knitr中使用。我是knitr的新手,可以创建图表等,但无法成功地将表格放入knitr文档中。
我的test.rnw文件目前如下:
\documentclass[11pt]{article}
\begin{document}

<<setup, echo = FALSE, results= 'hide', message = FALSE>>=
data(mtcars)

library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
@

\end{document}

我该如何在此文档中插入一个stargazer表格以展示数据框t的内容?
1个回答

13

您的意思是类似这样的吗(results='asis')?

\documentclass[11pt]{article}
\begin{document}

<<setup, echo = FALSE, results= 'hide', message = FALSE>>=
data(mtcars)

library(ggplot2)
qplot(speed, dist, data = cars) + geom_smooth()
@


<<results='asis'>>=
require(stargazer)
stargazer(mtcars, summary = FALSE)
@

\end{document}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接