Stargazer output is code, not a table

Deadly 提交于 2019-12-04 11:25:25

To render a stargazer table in pdf you can add this code to an empty R markdown (.Rmd) file:

---
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')

```

Which appears as:

Exporting to word involves the following (taken from 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.

Alternatively, if the appearance of the table doesn't matter too much you can put the following in an empty .Rmd file:

---
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')

```

Which results in a raw but readable table:

This happens because stargazer is designed to generate code. Thus, it is like a transpiler. You can save the HTML or LaTeX to file using the out argument and then render it in your internet browser or local LaTeX application. You can also render LaTeX online using Overleaf. While you can use stargazer with Word, I do not recommend doing so. The package is designed first and foremost for use in pure LaTeX documents. I've used it with both Word and LaTeX and there is no comparison. The results in LaTeX are lovely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!