Export the dataframe to a CSV

The write.csv() is an inbuilt function in R, we do not require installing any additional library for using this function.

In the code below, our write.csv() function takes 2 arguments, the first argument is the dataframe itself which is to be converted to a CSV file, the second argument is the path with “file_name.csv” which specifies the location where our CSV file will be saved with specified file_name.

Syntax: write.csv(dataFrame_name, “path\\file_name.csv”)

Code:

R




# sample dataframe
df <- data.frame(name = c("This", "is", "GFG"),
                 roll = c(10,20,30))
df
  
# saves the dataframe at the specified path
write.csv(df,"My_Path\\df.csv")


Output: 



How to export a DataFrame to Excel File in R ?

It is a frequent requirement to save our dataframe for portability after working on it on the auxiliary memory of the computer system using R Programming Language. In this article, we will be using writexl package to export our dataframe to excel(.xlsx). The write_xlsx() function of the writexl package is used to export our dataframe to an Excel file.

Similar Reads

Getting Started

The writexl is a simple package that contains a function write_xlsx() function which is used to write a dataframe to an Excel (.xlsx) file....

Export the dataframe to excel

Example 1: In the first line of the code below, we have used library(“writexl”) function to load the package named -> “writexl”. We have then used write_xlsx() function of the writexl library to export the dataframe to an Excel file. In the below example, our write_xlsx() function takes 2 arguments, the first argument is the dataframe itself which is to be converted to an Excel file, the second argument is the path with “file_name.xlsx” which specifies the location where our Excel file will be saved with specified file_name....

Export the dataframe to a CSV

...

Contact Us