The Wayback Machine - https://web.archive.org/web/20240623184548/https://www.geeksforgeeks.org/how-to-export-dataframe-to-csv-in-r/
Open In App

How to Export DataFrame to CSV in R ?

Last Updated : 26 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

R Programming language allows us to read and write data into various files like CSV, Excel, XML, etc. In this article, we are going to discuss how to Export DataFrame to CSV file in R Programming Language.

Approach: 

  • Write Data in column wise format
  • Create DataFrame for these data
  • Write Data to the CSV file
  • Print the success message

Function used:

  • dataframe() is used to create data frame

Syntax:

data.frame(column1, column2, column3)

  • write.csv() function is used create csv file from the data set.

Syntax:

 write.csv(dataframe, path) 

Example:

R




Rollno <- c("5", "6", "7")
Name <- c("John Doe","Jane Doe", "Bill Gates")
Marks <- c("80", "75", "95")
Age <- c("13", "13", "14")
  
  
df <- data.frame(Rollno,Name,Marks,Age)
  
write.csv(df,"C:\\Users\\...YOUR PATH...\\agedata.csv", row.names = FALSE)
  
print ('CSV created Successfully :)')


Output: 

Example:

R




Country <- c("China", "India", "United States", "Indonesia", "Pakistan")
  
Population <- c("1,407,068,600","1,374,506,881", "331,329,046", 
                "270,203,917", "225,200,000")
  
Date <- c("15 Mar 2021", "15 Mar 2021", "15 Mar 2021", 
          "30 Sep 2020", "1 Jul 2021")
  
df <- data.frame(Country, Population, Date)
  
write.csv(df,"C:\\Users\\...YOUR PATH...\\population.csv", row.names = FALSE)
  
print ('CSV created Successfully :)')


Output: 



Similar Reads

Export CSV File without Row Names in R
In this article, we will learn how to export CSV files without row names in R Programming Language. In R language we use write.csv() function to create a CSV file from the data. Syntax: write.csv(df, path) Parameters: df: dataframe objectpath: local path on your system where .csv file will be written/saved. For this, we have to create a dataframe w
1 min read
Export List to CSV or text File in R
In this article, we will discuss how to export a list to CSV and text file using R Programming language. Exporting to both of these types of files can be done using capture.output() function. This function is mainly used to evaluate its arguments with the output being returned as a character string or sent to a file. By just changing the file name
2 min read
Read contents of a CSV File in R Programming - read.csv() Function
read.csv() function in R Language is used to read "comma separated value" files. It imports data in the form of a data frame. Syntax: read.csv(file, header, sep, dec) Parameters: file: the path to the file containing the data to be imported into R. header: logical value. If TRUE, read.csv() assumes that your file has a header row, so row 1 is the n
3 min read
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 fi
3 min read
How to export dataframe to RDATA file in R?
In this, article we are going to save the information of a data frame in an RDATA file and display the information of the file using R Programming language. To save the information of a data frame in a file and display the information of the file in R language is as follows: Using the save function to save the file .RData format.Using the load() fu
3 min read
How to append a whole dataframe to a CSV in R ?
A data frame in R programming language is a tabular arrangement of rows and columns arranged in the form of a table. A CSV file also contains data stored together to form rows stacked together. Content can be read from and written to the CSV file. Base R contains multiple methods to work with these files. The write.csv() method overwrites the entir
3 min read
Export Plot to EPS File in R
An EPS file is a graphics file saved in the Encapsulated PostScript (EPS) file format. The EPS files may contain images, graphics, or even text. In this article, we will discuss how we export a plot to an EPS file using R programming language. Method 1 : Using setEPS() method The postscripts can be defined using the setEPS() method in R. postscript
2 min read
How to Export Multiple Dataframes to Different Excel Worksheets in R
In this article, we are going to see how to export multiple dataframe to different Excel Worksheets in R Programming Language. We will be using the xlsx module. The xlsx library provides R functions to read/write/format Excel files and their formats. The xlsx package gives programmatic control of Excel files. The modification of the sheet's compone
4 min read
How to Export Multiple Plots to PDF in R?
In this article, we will learn how to export multiple plots to a PDF in the R Programming Language. Save Multiple plots on different pages on PDF file: To save multiple plots in pdf we use the pdf() function to create and open a pdf file in the R Language. After this, whatever we do in the R console gets saved in the pdf file opened. The pdf() func
2 min read
How to export two HTML widgets in the same HTML page in R?
HTML widgets are interactive web components that can be embedded within an HTML document. They are created using R packages that provide bindings to JavaScript libraries. HTML widgets allow us to create dynamic and interactive visualizations, charts, maps, and others directly from R Programming Language.In order to install it, type the following in
14 min read
Article Tags :
three90RightbarBannerImg