Converting file formats using R

Q: How can I convert a data set from one format to another?library(rio)
convert(“U:/your path/your filename”,”U:/your path/new file name”)

Example for converting STATA data set to .CSV:

# Must install ‘rio’ package to use. install.packages(“rio”, lib = “U:/your path”)

install.packages(“rio”, lib = “U:/documents”)

library(rio)
convert(“U:/documents/my_file.dta”,”U:/documents/converted_file.csv”)

 

This method allows you to convert between many formats (e.g., Stata, SPSS, SAS, CSV, etc.). It uses the file extension to infer format and loads using the appropriate importing package. More info can be found on the R-project rio page.