Learn R Programming

sjmisc (version 2.0.1)

read_spss: Import SPSS dataset as data frame into R

Description

Import data from SPSS, including NA's, value and variable labels.

Usage

read_spss(path, atomic.to.fac = FALSE, tag.na = FALSE)

Arguments

path
File path to the data file.
atomic.to.fac
Logical, if TRUE, categorical variables imported from the dataset (which are imported as atomic) will be converted to factors.
tag.na
Logical, if TRUE, missing values are imported as tagged_na values; else, missing values are converted to regular NA (default behaviour).

Value

A data frame containing the SPSS data. Retrieve value labels with get_labels and variable labels with get_label.

Details

The atomic.to.fac option only converts those variables into factors that are of class atomic and which have value labels after import. Atomic vectors without value labels are considered as continuous and not converted to factors.

See Also

Examples

Run this code
## Not run: 
# # import SPSS data set. uses haven's read function
# mydat <- read_spss("my_spss_data.sav")
# 
# # use haven's read function, convert atomic to factor
# mydat <- read_spss("my_spss_data.sav", atomic.to.fac = TRUE)
# 
# # retrieve variable labels
# mydat.var <- get_label(mydat)
# 
# # retrieve value labels
# mydat.val <- get_labels(mydat)## End(Not run)

Run the code above in your browser using DataLab