Open In App
Related Articles

How to Import SPSS Files into R?

Improve Article
Improve
Save Article
Save
Like Article
Like

In this article, we are going to see how to import SPSS Files(.sav files) into R Programming Language.

Used file: Click

Method 1: Using haven Package

Here we will use the haven package to import the SAS files.

To install the package:

install.packages('haven')

To import the SAV file read_sav() methods are capable to read the file.

Syntax: 

read_sav(‘file’)

Example: Reading SPSS file

R




# import lib
library(haven)
  
data <- read_sav("airline_passengers.sav")                        
head(data)


Output:

number
112
118
132
129
121
135

Method 2: Using foreign Package

Foreign package has read.spss() methods to read the sav file in R Programming Language.

To install the package:

install.packages('foreign')

Syntax:

 read.spps(“File”, to.data.frame = TRUE/FALSE)

Example: Reading SPSS file 

R




library("foreign")
  
data1 <- read.spss("airline_passengers.sav"
                   to.data.frame = TRUE)
head(data1)


Output:

number
112
118
132
129
121
135

Method 3: Using Hmisc Package

Hmisc package have spps.get() methods to read the sav file in R Programming Language.

To install the package:

install.packages('Hmisc')

Syntax: 

spps.get(“File”, to.data.frame = TRUE/FALSE)

Example: Reading SPSS file

R




library("Hmisc")
  
data2 <- spss.get("airline_passengers.sav",
                  to.data.frame = TRUE)
head(data2)


Output:

number
112
118
132
129
121
135

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 04 Jan, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials