How to Export a Data Frame to CSV in R
In this tutorial, you will learn how to .
TLDR solution
write.csv(data_frame, "/target-path/file_name.csv", row.names=FALSE)
Example
Let's say, you have the following data frame:
df <- data.frame(fish = c("salmon", "pufferfish", "shark"),
count = c(5000, 200, 2)
)
print(df)
fish count
1 salmon 5000
2 pufferfish 200
3 shark 2
Let's save this data frame as csv file on your desktop:
write.csv(df, "/Users/DataToFish/Desktop/fish.csv", row.names=FALSE)
Adjust the target path and run your code and you should find a fish.csv file on your desktop.
That's it! You just learned how to save an r data frame as csv file.