How can we import data from SPSS into 'R' platform?

 Posted by Niladri.Biswas on 5/1/2013 | Category: Others Interview questions | Views: 1337 | Points: 40
Answer:

SPSS datasets can be imported into R via the read.spss() function in the foreign package . Also, we can use the spss.get() function in the Hmisc package.
spss.get() is a wrapper function that automatically sets many parameters of read.

First, download and install the Hmisc package .

install.packages("Hmisc")


Then use the following code to import the data:

library(Hmisc)

mydataframe <- spss.get("mydata.sav", use.value.labels=TRUE)


In this code, mydata.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 mydataframe is the resulting R data frame.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response