1.6 Loading Data from SPSS/SAS/Stata Files
1.6.2 Solution
The haven package has the function read_sav()
for reading SPSS files. To load data from an SPSS file:
# Only need to install the first time
install.packages("haven")
library(haven)
read_sav("datafile.sav") data <-
1.6.3 Discussion
The haven package also includes functions to read from other formats:
read_sas()
: SASread_dta()
: Stata
An alternative to haven is the foreign package. It also supports SPSS and Stata files, but it is not as up-to-date as the functions from haven. For example, it only supports Stata files up to version 12, while haven supports up to version 14 (the current version as of this writing).
The foreign package does support some other formats, including:
read.octave()
: Octave and MATLABread.systat()
:SYSTATread.xport()
: SAS XPORTread.dta()
: Stataread.spss()
: SPSS