Open In App

How to Export DataFrame to CSV in R ?

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: 



Function used:

Syntax:



data.frame(column1, column2, column3)

Syntax:

 write.csv(dataframe, path) 

Example:




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:




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: 


Article Tags :