Write a .csv file in R
Export .csv files: a native feature in R
Writing .csv. files is a basic feature in R programming. It's one of the most used method to export data from your R scripts. Two functions are available to write .csv files : write.csv() and write.table().
Export a .csv file in R with write.csv()
The write.csv() function is the basic function to write .csv files in R. Here is how it works:
write.csv(x = myDataset, file = "myFile.csv")
Your dataset will be exported at the root path of your work folder. With the default settings, the csv file will be exported with comma as separator and a dot for decimals. An alternative function, write.csv2(), is used for .csv files that use semicolon as a separator and a comma for the decimals.
Note that with the default parameters, row.names. and col.names parameters have the value TRUE. The first column and the first will be used as header of your file.
Write a .csv file in R with write.table()
Overall, the write.table() function works in the same way that the write.csv() function. Here is how it works.
write.table(x = myDataset, file = "myFile.csv")
What is the difference with the write.csv() function?
Its specificity is to be more customizable and more adapted to the export of uncommon formats.