Two problems with write.foreign (SPSS)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Open this post in threaded view
Report Content as Inappropriate

Two problems with write.foreign (SPSS)

Ulrich Keller

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

[hidden email] mailing list
PLEASE do read the posting guide!