ez.reads2: read spss

View source: R/io.R

ez.reads2R Documentation

read spss

Description

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

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

internally trim (leading and trailing) string spaces (The leading could be previously added by user, the trailing could come from SPSS padding to Width).
SPSS numeric -> R numeric
SPSS string (could be string of num) -> R character...then, when stringsAsFactors=T... -> R factor.
SPSS Type (numeric, string) matters, but Measure (scale, ordinal, nominal) seems to not matter
See param for more other details.
Also somehow auto replace irregular chars in the col names (eg, @–>.)

Usage

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

Arguments

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

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. Should generally be TRUE, because most R stuff does not auto recognize attr well.

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

not effective for this function, kept for compatiablity with other functions

Note

As of Nov, 2017, haven package eariler version is somewhat buggy, less powerful, but has been evolving a lot. I am not going to update haven right now. So stick with foreign. Potentially, one can also use SPSS R plugin to pass data between SPSS and R. see the "extra-variable" bug https://stackoverflow.com/a/7724879/2292993


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