Thanks again for your answer! I tried it out. write.foreign produces SPSS 
syntax, but unfortunally this syntax tells SPSS to take the names (and not the 
labels) in order to produce SPSS variable labels. The former labels get lost.

I tried a data frame produced by read.spss and one by spss.get. Here is the 
read.spss one (the labels meant to be exported are called "Text 1", ...):

jjread<-  read.spss("test2.sav", use.value.labels=TRUE, to.data.frame=TRUE)
> str(jjread)
`data.frame':   30 obs. of  3 variables:
 $ VAR00001: num  101 102 103 104 105 106 107 108 109 110 ...
 $ VAR00002: num  6 6 5 6 6 6 6 6 6 6 ...
 $ VAR00003: num  0 0 6 7 0 7 0 0 0 8 ...
 - attr(*, "variable.labels")= Named chr  "Text 1" "Text2" "text 3"
  ..- attr(*, "names")= chr  "VAR00001" "VAR00002" "VAR00003"
>      datafile<-tempfile()
>      codefile<-tempfile()
>      write.foreign(jjread,datafile,codefile,package="SPSS")
>      file.show(datafile)
>      file.show(codefile)


The syntax file I get is:

DATA LIST FILE= "C:\DOKUME~1\reinecke\LOKALE~1\Temp\Rtmp15028\file27910"  free
/ VAR00001 VAR00002 VAR00003  .

VARIABLE LABELS
VAR00001 "VAR00001" 
 VAR00002 "VAR00002" 
 VAR00003 "VAR00003" 
 .

EXECUTE.


I am working on R 2.2.0. But I think a newer version won ´t fix it either, will 
it?

Greetings,

Michael


-----Ursprüngliche Nachricht-----
Von: Chuck Cleland [mailto:[EMAIL PROTECTED] 
Gesendet: Mittwoch, 11. Januar 2006 17:16
An: Michael Reinecke
Cc: R-help@stat.math.ethz.ch
Betreff: Re: [R] SPSS and R ? do they like each other?

Michael Reinecke wrote:
> ... and is there also such a nice tool (like spss.get) for exporting 
> data frames to SPSS? write.table does not keep the data frame labels - 
> neither did the other exporting tools that I found.
> ... 

library(foreign)
?write.foreign

write.foreign(df, datafile, codefile, package = "SPSS")

   The codefile generated is SPSS syntax which will read the datafile and 
create SPSS variable and value labels.

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

______________________________________________
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

Reply via email to