The write_xlsx() from writexl library used to export data frame to excel file.

The following method shows how you can do it with syntax.

Method: Use write_xlsx() From writexl Package



The following example shows how to use write_xlsx() function in R.

Export Data Frame to Excel File Using write_xlsx() Function in R

To use write_xlsx() function you need to follow below steps:

Step 1: Create a Data Frame

Let’s first start with creating data frame:

# Create data frame
df <- data.frame("Cylinder"=c("cylinder1","cylinder2","cylinder3","cylinder4"),"Value"=c(12,10,13,14))

# Print data frame


 Cylinder Value
1 cylinder1    12
2 cylinder2    10
3 cylinder3    13
4 cylinder4    14

The output shows data frame created using data.frame() function.

Step 2 : Use write.excel() to Export Data Frame

Now start by installing required package and work according syntax:

# Install writexl package

# Import library

# Export data frame to Excel file

Note that we need use double backslashes (\) in the file path to avoid error. Here we doesn’t provide full path because file is in same folder where R studio is installed.