R — Data Export
CSV files
# Base R
write.csv(data, "output.csv", row.names = FALSE)
# readr
library(readr)
write_csv(data, "output.csv")
write_tsv(data, "output.tsv")
Excel files
library(writexl)
# Write Excel
write_xlsx(data, "output.xlsx")
# Multiple sheets
write_xlsx(
list(sheet1 = data1, sheet2 = data2),
"output.xlsx"
)
JSON files
library(jsonlite)
# Write JSON
json_data <- toJSON(data, pretty = TRUE, auto_unbox = TRUE)
write(json_data, "output.json")
Database
library(DBI)
library(RSQLite)
con <- dbConnect(SQLite(), "database.db")
# Write table
dbWriteTable(con, "users", data, overwrite = TRUE)
# Append to table
dbWriteTable(con, "users", new_data, append = TRUE)
dbDisconnect(con)
Mini Practice
Write R code that:
- Writes a data frame to CSV
- Writes multiple sheets to Excel
- Exports data as JSON
- Writes to a SQLite database
Up Next
In the next lesson, you'll learn about Statistics — basic statistical analysis in R.
Related Topics
Frequently Asked Questions about Data Export
What is Data Export in R?
Data Export is a fundamental concept in R. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Data Export?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Data Export.
Why is Data Export important in R?
Data Export is essential for R development. Understanding this concept will help you write better code and solve real-world problems more effectively.