[R] Two problems with write.foreign (SPSS)

Ulrich Keller uhkeller at web.de
Mon May 29 23:29:16 CEST 2006


Hello,

Working on a little primer to ease the transition from SPSS to R, I have 
encountered two problems with write.foreign.

One is cosmetic (but still annoying): the text data files will contain 
"NA" for missing values. Each time SPSS encounters an NA, it will print 
a warning. This could be easily avoided by calling write.table (which I 
suppose write.foreign uses) with na=",,". That's right, two commas.

The second is more serious: character variables are not read at all 
because they are not specified correctly in the SPSS syntax file. A 
string variable has to be specified with a preceding asterisk and a type 
and length indicator. Suppose mydf contained a numerical variable "a" 
and a string variable "b" with max(nchar(mydf$b))==10. What 
write.foreign(mydf,...,package="SPSS") writes is:

DATA FILE filename.dat free
/ a b.

What it should write, however, is:

DATA FILE filename.dat free
/ a * b (A10).



More information about the R-help mailing list