Output several regression tables into multiple pages of a Word document in R

≡放荡痞女 提交于 2020-04-14 07:28:19

问题


My goal is to create a multi-page Microsoft Word document with many formatted regression table outputs on consecutive pages. Ideally this would be done using R Markdown.

I have had some luck making nicely formatted regression tables in word using sjPlot::tab_model

So for example, I can do

mod2 <- lm(Petal.Length ~ Species + Petal.Width, data=iris) 
sjPlot::tab_model(mod2, file = "~/Desktop/model2.doc")

to create a nice-looking regression table in a new Word document.

If I do

mod3 <- lm(Petal.Length ~ Species + Petal.Width, data=iris) 
sjPlot::tab_model(mod2, file = "~/Desktop/model3.doc")

I can make a second Word document with another nicely formatted regression table.

The goal here is to create a single Word document containing both model outputs on consecutive pages.

I know that in R Markdown, I can make multi-page regression tables using Stargazer and Knit, e.g.,

stargazer(mod2)

But these only render in PDF or HTML.

I know that sjPlot doesn't directly knit to Word, so that's not an option.

Possible solutions include:

  1. Using a different package to render Word-compatible regression output tables in Markdown
  2. Finding a clever way to combine the tab_model outputs into a single Word document.
  3. Some other way I'm not thinking of.

回答1:


I figured it out. The best way is to stick with sjPlot, knit to HTML, then copy and paste from HTML to Word. The table renders nicely that way.

Thanks to Andrew Reece (andrew_reece) for this one.



来源:https://stackoverflow.com/questions/57405081/output-several-regression-tables-into-multiple-pages-of-a-word-document-in-r

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