R allows you to easily read and write data in different formats like CSV, Excel, and text files. This is essential for real-world data analysis. Unfortunately, we cannot recreate this functionality in our web editor but the below code snippets demonstrate how this would be done.
# Import a CSV file
data <- read.csv("data.csv")
# Import an Excel file
library(readxl)
data_excel <- read_excel("data.xlsx")
# Export to CSV
write.csv(data, "output.csv", row.names = FALSE)
# Export to Excel
library(writexl)
write_xlsx(data, "output.xlsx")
Using these functions, you can seamlessly move data between R and external files for analysis.