I'm using read.spss in the "foreign" package to read in a .sav file to R.
This is survey data coming from an online survey. However, the results (via the SPSS file) contains large areas of white space in fields (I assume from text entry fields on the online form) these appear when I use write.csv.
For reference, this is the code I'm using:
dataset <- read.spss(file.choose(), to.data.frame=TRUE)
csv <- write.csv(dataset, file=file.choose(), append=FALSE, na="NA", row.names=FALSE, fileEncoding="UTF-8")
Can I adjust this to replace the whitespace in the data frame with NA for my final csv output?
Resolved: discovered that using the
memisc
package and substituting my original read.spss function withdataset <- as.data.set(spss.system.file(file.choose()))
ordataset <- as.data.set(spss.portable.file(file.choose()))
avoids inputting large space character strings automatically. More here: Read SPSS file into R