Writing Files
In this page:
Writing Files
write.csv(df, "file.csv") writes a data frame out to a CSV file, and row.names = FALSE is commonly added to avoid writing an extra unnamed index column. This is the standard way to export processed data from R for use elsewhere. writeLines() is a lower-level alternative for writing plain text.
Note: Always pass row.names = FALSE to write.csv() unless you specifically want R's row index written as an extra column.
Example: Writing Files
df <- data.frame(name = c("Alice", "Bob"), age = c(30, 25))
write.csv(df, "output.csv", row.names = FALSE)
contents <- readLines("output.csv")
print(contents)
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: