readSpss: Read SPSS Data Files and Truncate Space in String Variables...

Description Usage Arguments Details Value Author(s)


This function reads SPSS data files using the function read.spss from the foreign package and converts all variables to class character. Additionally, leading and trailing white spaces can be removed from character variables, numeric values can be padded with leading zeros for uniform width of all entries in a column, and identifier variables can be renamed (i.e. when consistently named identifier varables are desired for automated merging of multiple datasets with mergeData).


readSpss(file, correctDigits = FALSE, truncateSpaceChar = TRUE, 
oldID = NULL, newID = NULL)



Name of the SPSS data file to be read in


Logical: whether values should be transformed to have uniform width in each column, see ‘Details’.


Logical: whether leading and trailing spaces should be removed from character variables.


Optional: A character string containing the ID name in the original SPSS dataset.


Optional: A character string containing the ID name after reading in the data.


If correctDigits=TRUE, the values in each column are transformed to have uniform width by adding leading zeros. The width of a column is determined by the longest value in this column, e.g., if a column contains the values 1, 10, 100 the transformed column will be 001, 010, 100. This can be useful if the values had leading zeros which were removed by reading in the SPSS file.

If oldID and newID are used, the ID variable in the SPSS dataset will be changed to newID when the file is read.


A data frame. All columns are of class character.


Nicole Haag, Sebastian Weirich

eatPrep documentation built on May 2, 2019, 5:20 p.m.

Related to readSpss in eatPrep...