Converting file formats using R

Q: How can I convert a data set from one format to another?

A: Install the R package “rio” and all of its associated packages, then run the following command using your own file location path.  Ensure that the /’s within the path are heading in the correct direction as shown below.

library(rio)
convert(“U:/your path/your filename”,”U:/your path/new file name”)

Example for converting STATA data set to .CSV:

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.


 
Quick Links