When working with other researchers you may come across data stored in a proprietary format such as an SPSS file. Don’t worry! R can read and write these files too.
To read and write SAS, SPSS, or Stata files you can use the haven
package, which is another member of the tidyverse. While it is possible to save data from R in other proprietary formats, we recommend using the CSV format, as it will be readable by most statistical software and will prevent any future worries about software versions preventing you from opening your data.
There are example data files from other stats software in the sample data folder at X:/Agency_Files/Outcomes/Risk_Eval_Air_Mod/_Air_Risk_Evaluation/R/R_Camp/Student Folder/Sample data/Other stats
. You can copy a few of the files to your R project to test the functions for yourself.
library(haven)
# SAS
read_sas("sas-data.sas7bdat")
write_sas(mtcars, "mtcars.sas7bdat")
# SPSS
read_sav("spss-data.sav")
write_sav(mtcars, "mtcars.sav")
# Stata
read_dta("stata-data.dta")
write_dta(mtcars, "mtcars.dta")
Theforeign
package reads and writes MiniTab and SYSTAT (SigmaPlot) files. When reading these file types you may end up with a list of multiple data items. To access one of the list items use brackets, such as data[1]
. You can also add the name of the item in the list after a $
sign, as in data$Control
. In some of these cases it may be easier to ask the original data owner to export a CSV file for you.
library(foreign)
# Minitab
read.mtp("minitab-data.mtp")
# SYSTAT and SigmaPlot
read.systat("systat-old-data.sys")
read.systat("systat-new-data.syd")
TheR.matlab
package will read and write Matlab files.
library(R.matlab)
# Matlab
readMat("matlab-data.mat2")
You’ve reached the end of this path. Return to the homepage and continue searching.