Make sure you have version of R >= 3.3.0 and install the packages tidyverse and rio
install.packages("tidyverse")
install.packages("rio")
The functions export() and import() in the rio package automatically choose the appropriate data read or write function based on file extension
library(rio)
Open a .csv:
| Stata | import delimited "filepath.csv" |
| R | import("filepath.csv") |
Save a .csv:
| Stata | export delimited using "newfilepath.csv", delimiters("\t") |
| R | export(df, "newfilepath.csv") |
| Stata | import excel "filepath.xls" |
| R | import("filepath.xls") |
library(rio)
# import Stata datasets
df <- import("http://www.nber.org/namcs/data/namcs2010.dta")
# import SAS datasets
df <- import("http://www.nber.org/namcs/data/namcs2010.sas7bdat")
Store your R dataframes in the feather format.
export("filepath.feather")
R also has proprietary formats like .rda and rds, but they are slower.