How to Write a Data Frame to CSV in R
· 1 min read · Updated March 14, 2026 · beginner
r csv data-export readr data.table
Writing data frames to CSV files is a standard task in R. Here are the main ways to do it.
With readr
The tidyverse readr package provides write_csv():
library(readr)
write_csv(df, "output.csv")
This writes without row names and handles strings cleanly.
With base R
write.csv(df, "output.csv", row.names = FALSE)
Set row.names = FALSE to avoid writing an X1 column with row numbers.
With data.table
For large datasets, data.table::fwrite() is significantly faster:
library(data.table)
fwrite(df, "output.csv")
# 0.26 sec for 1M rows
See Also
- data.frame — Base R data frame
- tibble — Tidyverse tibble