Importing Data from SPSS

Importing a SPSS (Statistical Package for the Social Sciences) data file into R / JGR is really straight forward.

Method 1 (JGR):

This method is very similar to opening a native R Data file (RDA file). In the data viewer, select open data:

dataviewer

Manoeuvre to the SPSS file (ie Data.sav) and open it.

The data should now import and become visible in the data viewer.

(the package ‘foreign’ 1 should be installed).

The data frame can subsequently be saved as an R file (from the data viewer).

Method 2 (Console) using the foreign package 1:

Use the foreign package 1 and read the file into R:

library(foreign)
MyData<- read.spss(‘/Users/paulcool/Desktop/Data.sav’,to.data.frame=TRUE)

And save as an R file:

save(MyData,file=’/Users/paulcool/Desktop/MyData.rda’)

Method 3 (Console) using the haven package 2:

install.packages(‘haven’)

library(haven)

You can open a SPSS file and put it into a dataframe in R by:

MyData <- read_spss(‘/Users/paulcool/Desktop/Data.sav’)

And save as an R file:

save(MyData,file=’/Users/paulcool/Desktop/MyData.rda’)

If you want to save your data file as a sav file, just do:

write_sav(MyData, ‘/Users/paulcool/Desktop/Data.sav’)

 

1.
R Core team. Foreign: Read Data stored by Minitab, S, SAS, SPSS, Stata, Systat, Weka, dBase, ... [Internet]. 2015. Available from: https://cran.r-project.org/web/packages/foreign/index.html
1.
Wickham H, Miller E, RStudio. haven: Import “SPSS”, “Stata” and “SAS” Files [Internet]. 2016. Available from: https://cran.r-project.org/web/packages/haven/index.html