[R] write.foreign and SPSS
ccleland at optonline.net
Tue Jul 5 21:07:07 CEST 2005
Erin Hodgess wrote:
> Dear R:
> In the foreign library, there is a function "write.foreign".
> When this is used to write to an SPSS file, there are
> actually 2 files as output: a data file and a code file.
> How would you coordinate these to become an SPSS sav file,
Using the warpbreaks dataset as an example, do the following in R:
write.foreign(warpbreaks, "c:/warpbreaks.dat", "c:/warpbreaks.sps",
In SPSS, open the syntax file "warpbreaks.sps". This syntax will
read in the data and apply variable and value labels to variables that
were factors in R. I find you often need to edit the syntax file
created by write.foreign just a bit in SPSS. Here is what write.foreign
produces for me:
DATA LIST FILE= c:/warpbreaks.dat free
/ breaks wool tension
You need to add some periods and quotation marks in critical places
for this to run properly in SPSS.
DATA LIST FILE= "c:/warpbreaks.dat" free
/ breaks wool tension .
tension "tension" .
3 "H" .
Once the data has been read in by running the code file, it can be
saved in the SPSS format.
> Thanks so much!
> R Version 2.1.0 Windows
> Erin Hodgess
> mailto: hodgess at gator.uhd.edu
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Chuck Cleland, Ph.D.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894
More information about the R-help