在Rstudio和Knitr中使用观星仪 [英] Using stargazer with Rstudio and Knitr

查看:104
本文介绍了在Rstudio和Knitr中使用观星仪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用RStudio在knitr中使用stargazer输出.例如,我将下面的代码粘贴到.Rmd文件中,然后单击编织HTML". [和]之间的第一个块表示为方程式.第二个区块来自观星者.它仍然是代码.当我将第二个代码块(少了[和])粘贴到Sweave文件中,然后单击编译为PDF"时,代码将渲染为表格.我已经安装了MikTex和Stargazer的第3版.

I'm struggling to use stargazer output in knitr, using RStudio. For example, I paste the code below into a .Rmd file, then click Knit HTML. The first block between [ and ] is rendered as equations. The second block is from stargazer. It remains as code. When I paste the second block, less [ and ], into a Sweave file and then click compile as PDF, the code renders as a table. I have MikTex installed and version 3 of Stargazer.

答案将stargazer或xable表插入到knitr文档中单击编译PDF时,在Sweave文件(Rnw)中为我工作.在Rmd文件中,单击编织HTML"时不会渲染tex.

The answer inserting stargazer or xable table into knitr document works for me in a Sweave file (Rnw) when clicking compile PDF. In an Rmd file, the tex is not rendered when clicking Knit HTML.

如何将stargazer输出放到Rmd文件中,以便Knit HTML将乳胶代码转换为表格? (我是Latex的新手,并且不确定可以删除哪些代码,因此对较长的一段代码表示歉意.)

How can I put stargazer output into a Rmd file so that Knit HTML converts the latex code to a table? (I'm new to Latex, and am not sure what code I can delete, so apologise for the long segment.)

\[
\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}
\]

\[
\documentclass{article}

\begin{document}


% Table created by StarGazer v.3.0.1 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Sun, Feb 03, 2013 - 11:34:52 AM
\begin{table}[htb] \centering 
  \caption{} 
  \label{} 
\footnotesize 

\begin{tabular}{@{\extracolsep{5pt}}lc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
\cline{2-2} 
\\[-1.8ex] & Rate \\ 
\hline \\[-1.8ex] 
 pole & $0.071^{***}$ \\ 
  & $(0.020)$ \\ 
  & \\ 
 post & $0.095^{***}$ \\ 
  & $(0.019)$ \\ 
  & \\ 
 Constant & $-5.784^{***}$ \\ 
  & $(1.667)$ \\ 
  & \\ 
\hline \\[-1.8ex] 
Observations & $46$ \\ 
Residual Std. Error & $2.378 (df = 43)$ \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\normalsize 
\end{tabular} 
\end{table} 

\end{document}
\]

推荐答案

由于该主题已过时,因此我认为当前的问题是以某种方式将stargazer与knitr结合使用,并且并不是将观星对象转换为HTML.

Since the topic has gone a bit stale, I'll assume the issue at hand is to somehow use stargazer with knitr, and not per se the conversion of the stargazer objects into HTML.

作为观星者的狂热爱好者,我提出了以下工作流程:

Being an avid fan of stargazer, I have come up with the following workflow:

  1. 将我的代码写入.Rmd文件中.
  2. 将其编织为.md. Stargazer表作为LaTeX代码保留在生成的降价文件中.
  3. 使用 pandoc 将markdown文件转换为PDF. Pandoc将LaTeX代码转换为适当的表.或者,可以将LyX与knitr插件配合使用,以PDF格式很好地输出观星台.
  1. Write my code in an .Rmd file.
  2. Knit it into .md. Stargazer tables remain as LaTeX code in the resulting markdown file.
  3. Use pandoc to convert the markdown file to PDF. Pandoc translates the LaTeX code into proper tables. Alternatively, one can use LyX with knitr plugin to get stargazer tables nicely output in PDF format.

如果要在MS Word中使用观星台,我发现的最好方法是使用 LaTeX2RTF .尽管最顶部的单元格有些变形,但解决此问题是要删除错误的空单元格.对于其余表,将保留该表并将其粘贴/导入到Word中.

If one wants stargazer tables in MS Word, the best way I have found is to use LaTeX2RTF. Although the very top cells are distorted a bit, fixing it is a matter of removing an erroneous empty cell. For the rest the table is preserved and can be pasted/imported into Word.

这两种策略有助于在LaTeX之外使用观星者.希望能帮助到你.

These two strategies help use stargazer outside LaTeX. Hope it helps.

这篇关于在Rstudio和Knitr中使用观星仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆