R – Export Data into a CSV File

While importing the data set from my local desktop file into R, I was wondering, if we can do the opposite i.e. exporting the DataSet from R to my local. Suppose, I do some changes to the data file in R and want to share the modified data file. So, what is the solution? 

So, here is an example of how to write a CSV file in R using write.csv():

Problem:
Export Data into CSV from R

Solution:
R allows exporting datasets from the R workspace into a CSV file and save it in a local directory.For that, we can use the function write.csv(). If the file with the same name already exists in the specified location, R overwrites the original file.

write.csv uses "." for a decimal point and a comma(,) for the separator.

I created a data frame in R called “titanic” using the dataset “Titanic.csv”. The steps are mentioned here. Now, I want to save the Data Frame data into a new CSV file named “Titanic_modified.csv” and save it to my local. This can be done by below code:



So, the above code created a new CSV file in my local.

If we don’t want to include the row names in the new CSV file created, we can use an argument named “row.names = FALSE”

Also, to omit ‘NA’s, we can use an argument a “na=””

Well, there are other options that can be used with write.csv(). Find out by using the command help(write.csv).
Thank You for reading!
0

Leave a Reply

Your email address will not be published. Required fields are marked *