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

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

Method: Use write.csv() Function

write.csv(dataframe,path_of_csv_file)

The following examples shows to export data frame to csv in R.

Using write.csv() Function

To use write.csv() function you need to follow below steps:

Step 1: Create a Data Frame

First let create data frame using data.frame() function:

# Create data frame
df <- data.frame(Product=c("Cylinder","Sensor","Display","Monitor"),Count=c(12,6,2,1))

# Print data frame
print(df)

Output:

 Product Count
1 Cylinder    12
2   Sensor     6
3  Display     2
4  Monitor     1

The output shows data frame that we created.

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

After creating data frame we can export it to csv file:

# Export data frame to CSV
write.csv(df,"product.csv",row.names=FALSE)

When we store data frame in CSV file it automatically assign row number to each row of CSV file to avoid that we use row.names which is assign as FALSE.