To export data frame to CSV file in R, you can use write.csv() function.

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

Method 1: Use write.csv() Function

write.csv(df,file_path)

The following example shows how to export data frame to csv file using write.csv() function.

Using write.csv() Function

Let’s see how we can use write.csv() function in R to export data frame to CSV file:

# Create dataframe
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 dataframe to csv
write.csv(df,"Machine1.csv",row.names=FALSE)

Here the above code shows how we can export data frame to CSV file using write.csv() function.