ez.reads: read spss

View source: R/io.R

ez.readsR Documentation

read spss

Description

ez.reads: haven (label,labels), usrna always to NA, col width >255 characters OK, Date, Time -> Date, hms/difftime

ez.reads2: foreign (variable.labels, value.labels), perserve initial usrna if necessary, col width >255 characters Bad, Date, Time -> numeric.

I hacked to trim (leading and trailing) string spaces (The leading spaces could be previously added by user, the trailing could come from SPSS padding to Width). Also, I hacked to auto replace col names (eg, @->.), see param makenames if one wants keep variable names as is.

Usage

ez.reads(
  path,
  atm2fac = 2,
  usrna = TRUE,
  tolower = FALSE,
  stringsAsFactors = FALSE,
  blanksAsNA = TRUE,
  na.strings = c("", "."),
  makenames = TRUE,
  ...
)

Arguments

path

File path to the data file

atm2fac

c(1,2,3). atomic means logic,numeric/double,integer,character/string etc. Char to factor controlled separately by stringsAsFactors.
1: atomic with a value labels attribute kept as is (eg, gender 1/2 numeric). SPSS value label kept as R attribute (Male/Female).
2: atomic with a value labels attribute converted to factor (eg, gender 1/2 factor). SPSS value label kept as R attribute (Male/Female). Should be desirable most of time.
3: atomic with a value labels attribute converted to factor, also factor values replaced by value labels (eg, gender Male/Female factor). No R attribute. Useful for plotting.

usrna

(unfortunately, no effect as of the underlying HAVEN v0.2.1/v1.1.0) if TRUE, honor/convert user-defined missing values in SPSS to NA after reading into R; if FALSE, keep user-defined missing values in SPSS as their original codes after reading into R.

tolower

whether to convert all column names to lower case

stringsAsFactors

T/F

blanksAsNA

T/F, converts factor or character vector elements to NA if matching na.strings

na.strings

only applicable if blanksAsNA=T. e.g., c(”,'.','NA','na','N/A','n/a','NaN','nan')

makenames

if F, keep as is. if T, call make.names(unique=TRUE,allow_=TRUE) _ kept, The character "X" is prepended if necessary. All invalid characters are translated to "." .1 .2 etc appended for uniqueness

Note

wrapper of sjmisc_read_spss, uderlying of which it uses HAVEN v0.2.1/v1.1.0


jerryzhujian9/zmisc documentation built on March 9, 2024, 12:49 a.m.