Read SPSS sav File into R
In this article, we are going to see how to read SPSS .sav File in R programming language. The SPSS Statistics File Format is a proprietary binary format, developed and maintained as the native format for the SPSS statistical software application.
The file used in the examples can be downloaded from here.
Method 1: Using read_sav() Function of haven Package:
To read SPSS files in R we use the read_sav() function. To do so we firstly install the haven package using:
install.packages("haven")Then, import haven package in R code and using read_sav() function read SPSS files.
Syntax:
read_sav(“FileName.sav”)
Example: Reading SPSS file
R
# import haven library package library("haven") # Use read_sav() function to read SPSS filedataframe <- read_sav("SPSS.sav") dataframe |
Output:
Method 2: Using read.spss() Function of foreign Package
To read SPSS files in R we use read_spss() function. To do so we firstly install foreign package using:
install.packages("foreign")Then, import foreign package in R code and using read_spss() function read SPSS files.
Syntax:
read_spss(“FileName.sav”, to.data.frame = BOOLEAN)
Example: Reading SPSS file
R
# import foreign packagelibrary("foreign") # Read SPSS file using read.spss() functiondataframe <- read.spss("SPSS.sav", to.data.frame = TRUE) dataframe |
Output:


