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

From: Ulrich Keller <uhkeller_at_web.de>
Date: Tue 30 May 2006 - 07:29:16 EST


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).

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue May 30 15:49:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 30 May 2006 - 20:10:20 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.