uhkeller at web.de
2006-Jun-01 11:31 UTC
[Rd] write.foreign (SPSS) does not handle NAs properly (PR#8927)
Full_Name: Ulrich Keller Version: 2.3.0 Patched (2006-04-28 r37936) OS: Windows XP SP2 Submission from: (NULL) (158.64.77.43) write.foreign(x,...,package="SPSS") writes incorrect data files if x contains NAs. Missing values are represented as "NA" in the file; SPSS will print an error every time it encounters an "NA". For example: <CODE>> x<-data.frame(v1=c(1,NA)) > library(foreign) > write.foreign(x,stdout(),stdout(),package="SPSS")1 NA DATA LIST FILE= "1" free / v1 . VARIABLE LABELS v1 "v1" . EXECUTE. </CODE> The first two lines after the call to write.foreign are the contents of the text data file that is written. The "NA" should not be there and would make SPSS generate an error. One solution would be to use commas instead of blanks as delimiters and "" or " " for NAs. The DATA LIST command would then be DATA LIST FILE=filename FREE (",")