Skip to content

Instantly share code, notes, and snippets.

@gzagatti
Created August 3, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gzagatti/da1c81a81f9323e0fd887dacd733d366 to your computer and use it in GitHub Desktop.
Save gzagatti/da1c81a81f9323e0fd887dacd733d366 to your computer and use it in GitHub Desktop.
Converting a list of SPSS files (.sav) to CSV using magrittr
library('magrittr')
library('memisc')
# get all .sav files from directory
files <- list.files('.', pattern='.sav$', recursive=FALSE)
# get the dataframes
dfs <- list.files('.', pattern='.sav$', recursive=FALSE) %>%
lapply(spss.system.file) %>%
lapply(as.data.set) %>%
lapply(data.frame)
# save the dataframes as csv
mapply(write.csv, dfs, gsub('.sav$', '.csv', files), SIMPLIFY=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment