There is a package foreign
with a function write.foreign()
that can write a SPS and CSV file. The SPS file than can read the CSV fiel into SPSS including labels. Fine so far, but there are some issues with that function:
DATA LIST
attr()
, these are lost.write.foreign()
stops if there are more than 255 in any variable.... an error message like this:
Error in if (any(lengths > 255L)) stop("Cannot handle character variables longer than 255") :
missing value where TRUE/FALSE needed
I spent a lot of time with that and then found a good posting (http://r.789695.n4.nabble.com/SPSS-export-in-R-package-foreign-td921491.html) to start on and make it better. Here's my result, I'd like to share with you.
To export an R data.frame to SPSS, use write_sav
from the haven package:
library(haven)
write_sav(mtcars, "mtcars.sav")