[R] write.foreign and SPSS
Chuck Cleland
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,
> please?
Using the warpbreaks dataset as an example, do the following in R:
library(foreign)
write.foreign(warpbreaks, "c:/warpbreaks.dat", "c:/warpbreaks.sps",
package="SPSS")
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
VARIABLE LABELS
breaks "breaks"
wool "wool"
tension "tension"
VALUE LABELS
/
wool
1 "A"
2 "B"
/
tension
1 "L"
2 "M"
3 "H"
EXECUTE.
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 .
VARIABLE LABELS
breaks "breaks"
wool "wool"
tension "tension" .
VALUE LABELS
/
wool
1 "A"
2 "B"
/
tension
1 "L"
2 "M"
3 "H" .
EXECUTE.
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
>
> Sincerely,
> Erin Hodgess
> mailto: hodgess at gator.uhd.edu
>
> ______________________________________________
> R-help at 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
>
>
--
Chuck Cleland, Ph.D.
NDRI, Inc.
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
mailing list