本文介绍了将stargazer或xable表插入knitr文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

> 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文档.

I would like to be able to use either stargazer or xtable to put this data frame t in the table format in knitr. I am new to knitr, I can create graphs, etc. but am unable to successfully put tables to knitr document.

到目前为止,我的test.rnw文件看起来像这样:

My test.rnw file looks like this so far:

\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数据框的内容?

How would I insert a stargazer table into this document to display the contents of the t data frame?

推荐答案

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

Do you mean something like this (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}

这篇关于将stargazer或xable表插入knitr文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 17:29