Open In App

Read SPSS sav File into R

Improve
Improve
Like Article
Like
Save
Share
Report

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. 

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 file
dataframe <- 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 package
library("foreign")
  
# Read SPSS file using read.spss() function
dataframe <- read.spss("SPSS.sav", to.data.frame = TRUE
dataframe


Output:


Last Updated : 20 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads