Stargazer output is code, not a table

前端 未结 2 592
终归单人心
终归单人心 2021-01-02 23:00

I am trying to use the package stargazer in RStudio to generate a summary table of my data. For some reason, I am not able to view the table in the output when I use either

相关标签:
2条回答
  • 2021-01-02 23:52

    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.

    0 讨论(0)
  • 2021-01-02 23:54

    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:

    stargazer table in pdf doc

    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:

    raw stargazer table in word

    0 讨论(0)
提交回复
热议问题