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.