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.
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
library ( "haven" )
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
library ( "foreign" )
dataframe <- read.spss ( "SPSS.sav" , to.data.frame = TRUE )
dataframe
|
Output:
Last Updated :
20 Mar, 2024
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...