2013-01-18 25 views
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文档。插入stargazer或xable表格到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} 

我怎么会插入一个观星表到这个文件显示t数据帧的内容是什么?

回答

12

你的意思是这样的(结果='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}