Writing to Excel from R
quick tips
Spending your days R but working closely with analysts and leadership that live in Excel? Get familiar with openxlsx.
openxlsx
is an awesome package for writing multiple datasets to multiple sheets of an Excel workbook, and allows for robust styling and cell formatting. I found a tutorial on RPubs written by Ezekiel Adebayo Ogundepo covering this package that I often use at work. Definitely bookmark worthy.
Here is a high-level code example:
library(openxlsx)
# Name the Excel worksheets where you want to export data to
<- list("Overall Summary" = df_1, "LOB Summary" = df_2, "Details" = df_3)
list_of_datasets
# Save the Excel workbook to your wd with your worksheet list and name the Excel file
write.xlsx(list_of_datasets, "Excel_Workbook_2017.01.20.xlsx")
Links:
- Ezekiel’s openxlsx tutorial on RPubs
- openxlsx repository on GitHub