Learn R Programming

sjmisc (version 1.5)

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, attach.var.labels = FALSE,
  atomic.to.fac = FALSE, keep.na = FALSE, option = "haven")

Arguments

path
File path to the data file.
enc
File encoding of the SPSS dataset. Not needed if option = "haven" (default).
attach.var.labels
Logical, if TRUE, variable labels will automatically be added to each variable as "variable.label" attribute. Use this parameter, if option = "foreign", where variable labels are added as list-attribute to the import
atomic.to.fac
Logical, if TRUE, factor variables imported from the dataset (which are imported as atomic) will be converted to factors.
keep.na
Logical, if TRUE, user-defined missing values will be left as their original codes. If FALSE (default), corresponding values are converted to NA.
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 for

Value

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

See Also

  • http://www.strengejacke.de/sjPlot/datainit/{sjPlot manual: data initialization}
  • http://www.strengejacke.de/sjPlot/labelleddata/{sjPlot-manual: working with labelled data}
  • 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_label(mydat)

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

Run the code above in your browser using DataLab