[R] Please help with write.foreign(SPSS)

Jim Lemon jim at bitwrit.com.au
Tue Dec 7 09:19:38 CET 2010


On 12/07/2010 09:45 AM, He wrote:
> Dear all,
>
> I get stuck when i try to export the data into SPSS format/file using
> "write.foreign()"
> Do you know how to do it exactly?
>
> What i have done is
> 1) First i type the following code in R:
>
> df<-data.frame(id,year,res1)
> names(df)<-c("idcode","year","resarrvl")
> write.foreign(df,"z:/daten/res.dat","z:/daten/res.sps",package="SPSS")
>
> 2) Then I run "res.sps" in SPSS
>
> DATA LIST FILE= "k:/res.dat"  free (",")
> / idcode year resarrvl  .
>
> VARIABLE LABELS
> idcode "idcode"
>   year "year"
>   resarrvl "resarrvl"
>   .
>
> VALUE LABELS
> /
> idcode
> 1 "000CF7CC"
>   2 "000D0212"
>   3 "000D055F"
> ......
>
> 1339 "06996BC5"
>   1340 "069972BF"
> .
>
> EXECUTE.
>
> 3) After running this file, there automatically appears a SPSS file.
> The variable name is correct, however, there is no data in that file.
> The character variable id has different "values" like 1.00 =
> "000CF7CC", where 000CF7CC should be in the tab of data view instead
> of variable view.
>
> 4) Try to open "res.dat"
> It comes out the window "Text import wizard"
> The first column which should be the vairable id, shows only the
> "values" of id, i.e. 1, 2 and so on. And no real variables names.
>
Hi He,
Your data list statement looks like it is trying to read in a non-SPSS 
file (maybe a CSV file). Are you sure you want to do this?

Jim



More information about the R-help mailing list