Stargazer 输出是代码,而不是 table
Stargazer output is code, not a table
我正在尝试使用 RStudio 中的 stargazer 包来生成我的数据的摘要 table。出于某种原因,当我使用 html 或乳胶代码时,我无法在输出中查看 table,但当我输出为文本时可以看到它。
一个例子:
library(stargazer)
stargazer(attitude, type = 'text')
输出看起来像(应该是这样):
##
## =====================================
## Statistic N Mean St. Dev. Min Max
## -------------------------------------
## rating 30 64.633 12.173 40 85
## complaints 30 66.600 13.315 37 90
## privileges 30 53.133 12.235 30 83
## learning 30 56.367 11.737 34 75
## raises 30 64.633 10.397 43 88
## critical 30 74.767 9.895 49 92
## advance 30 42.933 10.289 25 72
## -------------------------------------
将其设置为乳胶:
stargazer(attitude, type = 'latex')
给出输出:
##
## % Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
## % Date and time: Wed, Aug 16, 2017 - 4:28:34 PM
## \begin{table}[!htbp] \centering
## \caption{}
## \label{}
## \begin{tabular}{@{\extracolsep{5pt}}lccccc}
## \[-1.8ex]\hline
## \hline \[-1.8ex]
## Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \
## \hline \[-1.8ex]
## rating & 30 & 64.633 & 12.173 & 40 & 85 \
## complaints & 30 & 66.600 & 13.315 & 37 & 90 \
## privileges & 30 & 53.133 & 12.235 & 30 & 83 \
## learning & 30 & 56.367 & 11.737 & 34 & 75 \
## raises & 30 & 64.633 & 10.397 & 43 & 88 \
## critical & 30 & 74.767 & 9.895 & 49 & 92 \
## advance & 30 & 42.933 & 10.289 & 25 & 72 \
## \hline \[-1.8ex]
## \end{tabular}
## \end{table}
最后,将其设置为 html:
stargazer(attitude, type = 'html')
给出输出:
##
## <table style="text-align:center"><tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Statistic</td><td>N</td><td>Mean</td><td>St. Dev.</td><td>Min</td><td>Max</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">rating</td><td>30</td><td>64.633</td><td>12.173</td><td>40</td><td>85</td></tr>
## <tr><td style="text-align:left">complaints</td><td>30</td><td>66.600</td><td>13.315</td><td>37</td><td>90</td></tr>
## <tr><td style="text-align:left">privileges</td><td>30</td><td>53.133</td><td>12.235</td><td>30</td><td>83</td></tr>
## <tr><td style="text-align:left">learning</td><td>30</td><td>56.367</td><td>11.737</td><td>34</td><td>75</td></tr>
## <tr><td style="text-align:left">raises</td><td>30</td><td>64.633</td><td>10.397</td><td>43</td><td>88</td></tr>
## <tr><td style="text-align:left">critical</td><td>30</td><td>74.767</td><td>9.895</td><td>49</td><td>92</td></tr>
## <tr><td style="text-align:left">advance</td><td>30</td><td>42.933</td><td>10.289</td><td>25</td><td>72</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr></table>
所以 R 正在生成代码,而不是 table。有谁知道为什么会这样?不幸的是,我在一台不允许我访问互联网的计算机上执行此操作,因此我不得不通过 cran 和 usb 驱动器手动安装所有软件包,因此在安装所需的各种软件包时我可能会遗漏一些东西。
我的最终目标是生成一个 table 可以导出为 pdf 或 word 文档,可能作为 r markdown 脚本的一部分。所以我的问题真的是为什么我不能生成 html 或 latex table?
要以 pdf 格式呈现观星者 table,您可以将此代码添加到一个空的 R markdown (.Rmd) 文件中:
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(stargazer)
```
Here is the latex table in a PDF document:
```{r mylatextable, results = "asis"}
stargazer(attitude, type = 'latex')
```
显示为:
导出到 word 涉及以下内容(摘自 help(stargazer)
):
To include stargazer tables in Microsoft Word documents (e.g., .doc or .docx), please follow the following procedure: Use the out argument to save output into an .htm or .html file. Open the resulting file in your web browser. Copy and paste the table from the web browser to your Microsoft Word document.
或者,如果 table 的外观不太重要,您可以将以下内容放入一个空的 .Rmd 文件中:
---
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(stargazer)
```
Stargazer table in microsoft word:
```{r word_table, comment = ''}
stargazer(attitude, type = 'text')
```
这会导致原始但可读 table:
发生这种情况是因为 stargazer
旨在生成代码。因此,它就像一个转译器。您可以使用 out
参数将 HTML 或 LaTeX 保存到文件,然后在您的互联网浏览器或本地 LaTeX 应用程序中呈现它。您还可以使用 Overleaf 在线渲染 LaTeX。虽然可以在 Word 中使用 stargazer
,但我不建议这样做。该软件包首先是为在纯 LaTeX 文档中使用而设计的。我已经将它与 Word 和 LaTeX 一起使用,没有可比性。 LaTeX 中的结果很可爱。
我正在尝试使用 RStudio 中的 stargazer 包来生成我的数据的摘要 table。出于某种原因,当我使用 html 或乳胶代码时,我无法在输出中查看 table,但当我输出为文本时可以看到它。
一个例子:
library(stargazer)
stargazer(attitude, type = 'text')
输出看起来像(应该是这样):
##
## =====================================
## Statistic N Mean St. Dev. Min Max
## -------------------------------------
## rating 30 64.633 12.173 40 85
## complaints 30 66.600 13.315 37 90
## privileges 30 53.133 12.235 30 83
## learning 30 56.367 11.737 34 75
## raises 30 64.633 10.397 43 88
## critical 30 74.767 9.895 49 92
## advance 30 42.933 10.289 25 72
## -------------------------------------
将其设置为乳胶:
stargazer(attitude, type = 'latex')
给出输出:
##
## % Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
## % Date and time: Wed, Aug 16, 2017 - 4:28:34 PM
## \begin{table}[!htbp] \centering
## \caption{}
## \label{}
## \begin{tabular}{@{\extracolsep{5pt}}lccccc}
## \[-1.8ex]\hline
## \hline \[-1.8ex]
## Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \
## \hline \[-1.8ex]
## rating & 30 & 64.633 & 12.173 & 40 & 85 \
## complaints & 30 & 66.600 & 13.315 & 37 & 90 \
## privileges & 30 & 53.133 & 12.235 & 30 & 83 \
## learning & 30 & 56.367 & 11.737 & 34 & 75 \
## raises & 30 & 64.633 & 10.397 & 43 & 88 \
## critical & 30 & 74.767 & 9.895 & 49 & 92 \
## advance & 30 & 42.933 & 10.289 & 25 & 72 \
## \hline \[-1.8ex]
## \end{tabular}
## \end{table}
最后,将其设置为 html:
stargazer(attitude, type = 'html')
给出输出:
##
## <table style="text-align:center"><tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">Statistic</td><td>N</td><td>Mean</td><td>St. Dev.</td><td>Min</td><td>Max</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">rating</td><td>30</td><td>64.633</td><td>12.173</td><td>40</td><td>85</td></tr>
## <tr><td style="text-align:left">complaints</td><td>30</td><td>66.600</td><td>13.315</td><td>37</td><td>90</td></tr>
## <tr><td style="text-align:left">privileges</td><td>30</td><td>53.133</td><td>12.235</td><td>30</td><td>83</td></tr>
## <tr><td style="text-align:left">learning</td><td>30</td><td>56.367</td><td>11.737</td><td>34</td><td>75</td></tr>
## <tr><td style="text-align:left">raises</td><td>30</td><td>64.633</td><td>10.397</td><td>43</td><td>88</td></tr>
## <tr><td style="text-align:left">critical</td><td>30</td><td>74.767</td><td>9.895</td><td>49</td><td>92</td></tr>
## <tr><td style="text-align:left">advance</td><td>30</td><td>42.933</td><td>10.289</td><td>25</td><td>72</td></tr>
## <tr><td colspan="6" style="border-bottom: 1px solid black"></td></tr></table>
所以 R 正在生成代码,而不是 table。有谁知道为什么会这样?不幸的是,我在一台不允许我访问互联网的计算机上执行此操作,因此我不得不通过 cran 和 usb 驱动器手动安装所有软件包,因此在安装所需的各种软件包时我可能会遗漏一些东西。
我的最终目标是生成一个 table 可以导出为 pdf 或 word 文档,可能作为 r markdown 脚本的一部分。所以我的问题真的是为什么我不能生成 html 或 latex table?
要以 pdf 格式呈现观星者 table,您可以将此代码添加到一个空的 R markdown (.Rmd) 文件中:
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(stargazer)
```
Here is the latex table in a PDF document:
```{r mylatextable, results = "asis"}
stargazer(attitude, type = 'latex')
```
显示为:
导出到 word 涉及以下内容(摘自 help(stargazer)
):
To include stargazer tables in Microsoft Word documents (e.g., .doc or .docx), please follow the following procedure: Use the out argument to save output into an .htm or .html file. Open the resulting file in your web browser. Copy and paste the table from the web browser to your Microsoft Word document.
或者,如果 table 的外观不太重要,您可以将以下内容放入一个空的 .Rmd 文件中:
---
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(stargazer)
```
Stargazer table in microsoft word:
```{r word_table, comment = ''}
stargazer(attitude, type = 'text')
```
这会导致原始但可读 table:
发生这种情况是因为 stargazer
旨在生成代码。因此,它就像一个转译器。您可以使用 out
参数将 HTML 或 LaTeX 保存到文件,然后在您的互联网浏览器或本地 LaTeX 应用程序中呈现它。您还可以使用 Overleaf 在线渲染 LaTeX。虽然可以在 Word 中使用 stargazer
,但我不建议这样做。该软件包首先是为在纯 LaTeX 文档中使用而设计的。我已经将它与 Word 和 LaTeX 一起使用,没有可比性。 LaTeX 中的结果很可爱。