问题
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:
- Using a different package to render Word-compatible regression output tables in Markdown
- Finding a clever way to combine the
tab_modeloutputs into a single Word document. - 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