Created
August 3, 2017 02:35
-
-
Save gzagatti/da1c81a81f9323e0fd887dacd733d366 to your computer and use it in GitHub Desktop.
Converting a list of SPSS files (.sav) to CSV using magrittr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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