How to Write a Data Frame to Excel in R

03.30.2021

R provides many ways for us to export our data. One common option is exporting to a n Excel file. In this article, we will learn how to export a data frame to in Excel file in R.

To export a data frame to an Excel file, we can use the write.xlsx method from the openxlsx library. We then pass the data frame, the sheet name, and the file name to this method.

library(openxlsx)

write.xlsx(df,
           sheetName = "sheet1",
           file = "data.xlsx")

The result will be a local Excel file with out data frame added to the sheet named "sheet1".