Export Data in R: Methods Explained

In R language, you can export data using the following methods:

  1. You can export a data frame as a text file with the write.table() function, and choose to export it in formats such as .csv or .txt.
write.table(data, file = "data.csv", sep = ",", row.names = FALSE)
  1. Export the data frame as a .csv file using the write.csv() function.
write.csv(data, file = "data.csv", row.names = FALSE)
  1. In order to export a data frame as an Excel file using the write.xlsx() function, you will need to install the openxlsx package.
library(openxlsx)
write.xlsx(data, file = "data.xlsx")
  1. Save the data object as an RDS file using the saveRDS() function.
saveRDS(data, file = "data.rds")
  1. Save the object in a .RData file using the save() function.
save(data, file = "data.RData")
bannerAds