Learn R Programming

sjmisc (version 1.0.2)

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, enc = NA, autoAttachVarLabels = FALSE,
  atomic.to.fac = FALSE, option = "haven")

Arguments

path
The file path to the SPSS dataset.
enc
The file encoding of the SPSS dataset. Not needed if option = "haven" (default).
autoAttachVarLabels
if TRUE, variable labels will automatically be attached to each variable as "variable.label" attribute. Use this parameter, if option = "foreign", where variable labels are attached as list-attribute to the imported
atomic.to.fac
Logical, if TRUE, factor variables imported from SPSS (which are imported as atomic) will be converted to factors.
option
string, indicating which package will be used to read the SPSS data file. By default, option = "haven", which means, the read_spss function from the haven package is used. Use option = "foreign" to use f

Value

See Also

  • http://www.strengejacke.de/sjPlot/datainit/{sjPlot manual: data initialization}
  • http://www.strengejacke.de/sjPlot/view_spss/{sjPlot manual: inspecting (SPSS imported) data frames}
  • write_spss

Examples

Run this code
# import SPSS data set. uses haven's read function
# by default
mydat <- read_spss("my_spss_data.sav")

# use foreign's read function
mydat <- read_spss("my_spss_data.sav",
                   enc = "UTF-8",
                   option = "foreign")

# 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_var_labels(mydat)

# retrieve value labels
mydat.val <- get_val_labels(mydat)

Run the code above in your browser using DataLab