To export data frame to an excel file in R, you can use write_xlsx() function from writexl package.

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

Method: Use write.xlsx() Function

library(writexl)

write_xlsx(df,file_path)

The following example shows how to export data frame to an excel using write_xlsx() function in R.

Using write_xlsx() Function

Let’s see how we can use write_xlsx() function to export a data frame to an excel in R:

# Import library
library(writexl)

# Create data frame
df<-data.frame(Date=c("21-10-2023","22-10-2023","23-10-2023","24-10-2023","01-11-2023","02-11-2023","03-11-2023","04-11-2023"),
               Machine_type=c("Mach_1","Mach_2","Mach_3","Mach_4","Mach_A","Mach_B","Mach_C","Mach_D"),
               Status=c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,FALSE),
               Pressure=c(11,12,10,11,89,85,87,90),
               Temperature=c(45.6,47.2,46.1,46.85,10.1,12.8,13.74,9.55))


# Export data frame to excel
write_xlsx(df,"Machine1.xlsx")

Here the above code shows how to export data frame to excel file in R.