Stargazer output is code, not a table

前端 未结 2 612
终归单人心
终归单人心 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: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

提交回复
热议问题