Search code examples
rspss

Trying to read an SPSS file in to R. Turns into all NAs. Errors inside


I am trying to read an SPSS file in to R using read.spss. It is a very large file (The World Values Survey), with about 67k entries.

Here is the code, with the errors:

> library(foreign)
> wvs = read.spss("C:/wvs2005_v20090901a.sav",to.data.frame=TRUE)
Warning messages:
1: In read.spss("C:/wvs2005_v20090901a.sav", to.data.frame = TRUE) :
C:/wvs2005_v20090901a.sav: Unrecognized record type 7, subtype 8 encountered in system file
2: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
3: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
4: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
5: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
6: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
7: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
8: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore
9: In `levels<-`(`*tmp*`, value = c("Missing; Unknown", "Not asked",  :
duplicated levels will not be allowed in factors anymore

Any insight is much appreciated.


Solution

  • Did you try a different function to read in spss? I found two:

    from ?read.spss A different interface also based on the PSPP codebase is available in package ‘memisc’: see its help for ‘spss.system.file’.

    Also, in package Hmisc, there is a function spss.get, which provides "Enhanced Importing of SPSS files".

    I recommend trying Hmisc::spss.get first.