[R] read.spss (package foreign) and character columns

Douglas Bates bates at stat.wisc.edu
Wed Aug 27 19:05:03 CEST 2003


RINNER Heinrich <H.RINNER at tirol.gv.at> writes:

> Dear R users!
> 
> I am using R Version 1.7.1, Windows XP, package "foreign" (Version: 0.6-1),
> SPSS 11.5.1.
> 
> There is one thing I noticed with "read.spss", and I'd like to ask if this
> is considered to be a feature, or possibly a bug:
> When reading character columns, character strings seem to get filled with
> blanks at the end.
> 
> Simple example:
> In SPSS, create a file with one variable called "xchar" of type "A5"
> (character of length 5), and  3 values ("a", "ab", "abcde"), save it as
> "test.sav".
> 
> In R:
> > library(foreign)
> > test <- read.spss("test.sav", to.data.frame=T)
> > test
>   XCHAR
> 1 a    
> 2 ab   
> 3 abcde
> > levels(test$XCHAR)
> [1] "a    " "ab   " "abcde"
> 
> Shouldn't it rather be "a" "ab" "abcde" (no blanks)?

I believe they are being saved as fixed length strings in the SPSS
file and R is just reading what it was given.




More information about the R-help mailing list