You can use the read_sav()
function from the haven library to read SPSS files in R. The syntax of the function is as follows.
read_sav("file_name.sav")
Step 1: Install haven library
The first step is to install the library of “haven” into your local computer.
install.packages('haven')
Step 2: Library it in R Studio
As for other libraries, you need to include it in the R Studio environment, assuming you are using R Studio.
library(haven)
Step 3: Use read_sav() function
Use the read_sav() to read a data file. We can use an SAV file of job_satisfaction.sav from the textbook Advanced and Multivariate Statistical Methods for Social Science Research as an example to show the result. You can download it into your current R Studio working directory, and then run the following R code.
read_sav("job_satisfaction.sav")
The following is the output. We can see that we import the SAV file as a data frame in R, which has 218 rows of data and 25 variables.
> read_sav("job_satisfaction.sav")
# A tibble: 218 x 25
Gender Age MStatus `Children#` Education Ethnicity
<dbl+lbl> <dbl> <dbl+lbl> <dbl> <dbl+lbl> <dbl+lbl>
1 1 [FEMALE] 37 1 [MARRIED] 2 1 [BSW/B~ 0 [JEWS]
2 0 [MALE] 56 1 [MARRIED] 3 1 [BSW/B~ 0 [JEWS]
3 1 [FEMALE] 32 1 [MARRIED] 3 1 [BSW/B~ 1 [ARABS]
4 0 [MALE] 30 1 [MARRIED] 1 1 [BSW/B~ 1 [ARABS]
5 1 [FEMALE] 41 1 [MARRIED] 2 1 [BSW/B~ 0 [JEWS]
6 1 [FEMALE] 55 1 [MARRIED] 2 1 [BSW/B~ 0 [JEWS]
7 1 [FEMALE] 27 1 [MARRIED] 0 1 [BSW/B~ 0 [JEWS]
8 1 [FEMALE] 34 1 [MARRIED] 2 1 [BSW/B~ 0 [JEWS]
9 1 [FEMALE] 49 1 [MARRIED] 3 1 [BSW/B~ 0 [JEWS]
10 0 [MALE] 51 1 [MARRIED] 1 1 [BSW/B~ 0 [JEWS]
# ... with 208 more rows, and 19 more variables: Yeas# <dbl>,
# Location <dbl+lbl>, MStatus_Rec <dbl+lbl>,
# Education_Rec <dbl+lbl>, Satisfaction <dbl>,
# Burnout <dbl>, Turnover <dbl>, Colleague <dbl>,
# Supervision <dbl>, Salary <dbl>, Promotion <dbl>,
# Autonomy <dbl>, RoleConflict <dbl>, Comfort <dbl>,
# WorkLoad <dbl>, AnyChild <dbl+lbl>, North <dbl+lbl>, ...