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.

 

Previous articleUseful functions for working with data objects in R
Next articleHow To Shop For CBD On Black Friday?
Author and Assistant Professor in Finance, Ardent fan of Arsenal FC. Always believe "The only good is knowledge and the only evil is ignorance - Socrates"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments