Home Data Science

Importing data from SPSS in R

SPSS is one of the popular statistical package used for data analysis. But remember you have to pay a huge amount to buy this software. The SPSS datasets can be imported into R using read.spss() function in foreign package .

Alternatively, you can use the spss.get() function in the Hmisc package .

spss.get() is a wrapper function that automatically sets many parameters of read.spss() for you, making the transfer easier and more consistent with what data analysts expect as a result.

First, download and install the Hmisc package, foreign package is already installed by default in R

install.packages("Hmisc")

Then use the following code to import the data:

library(Hmisc)
dataframe <- spss.get("sample.sav", use.value.labels=TRUE)

In this code, sample.sav is the SPSS data file to be imported, use.value.
labels=TRUE tells the function to convert variables with value labels into R factors with those same levels, and dataframe is the resulting R data frame.

 

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
Exit mobile version