read_spss: Import data from other statistical software packages

Description Usage Arguments Details Value Note See Also Examples

Description

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

Usage

1
2
3
4
5
read_spss(path, atomic.to.fac = FALSE, tag.na = FALSE)

read_sas(path, path.cat = NULL, atomic.to.fac = FALSE, enc = NULL)

read_stata(path, atomic.to.fac = FALSE, enc = NULL)

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).

path.cat

Optional, the file path to the SAS catalog file.

enc

The character encoding used for the file. This defaults to the encoding specified in the file, or UTF-8. Use this argument to override the default encoding stored in the file.

Details

These read-functions behave slightly differently from haven's read-functions:

  • The vectors in the returned data frame are of class atomic, not of class labelled. The labelled-class might cause issues with other packages.

  • When importing SPSS data, variables with user defined missings won't be read into labelled_spss objects, but imported as tagged NA values.

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.

Value

A data frame containing the imported, labelled data. Retrieve value labels with get_labels and variable labels with get_label.

Note

These are wrapper functions for haven's read_*-functions.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 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)


Search within the sjmisc package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.