I use the package "gtsummary" to produce to look at the balance across treatments in my data frame. However, the result is an image in the viewer. How can I export the result into word to use it directly in my paper?
Below is the command I used for the summary table:
Bal_ana <- data %>% select(a_pri, a_org, a_rfa,a_cfi, ana_pri,ana_org,ana_rfa,ana_cfi,n_ana, Treatment)
Bal_anatable <-
tbl_summary(
Bal_ana,
by = Treatment, # split table by group
missing = "no" # don't list missing data separately
) %>%
add_n() %>% # add column with total number of non-missing observations
add_p() %>% # test for a difference between groups
modify_header(label = "Variable") %>% # update the column header
bold_labels()
The kableExtra package recommended (01-2018) that the way to get output tables into a Word document is to copy/paste HTML table output from the Viewer directly into an open Word doc.
Another option is to just use the rtf_output format that opens in Word (as an RTF file, which could then be saved as a .docx file, for instance).
The knitr::kable() function is able to produce native table code for Word documents, and, the pander package also has this capability (with more options for table output). Here is a document that describes how: Happy collaboration with Rmd to docx.