Created
March 17, 2021 14:49
-
-
Save jamespaultg/9b5e312b135372b4f50ab46acf4e9b6b to your computer and use it in GitHub Desktop.
Convert SPSS files to CSV using R
This file contains hidden or 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(foreign) | |
| # Converting one SPSS file | |
| data <- read.spss("File_path_SPSS.sav", | |
| reencode='utf-8', | |
| use.value.labels = FALSE, | |
| to.data.frame = TRUE) | |
| head(data) | |
| View(data) | |
| write.csv2(data,"C:/Users/LYCJPG1/Documents/survey_results.csv") | |
| # Converting many SPSS file in a folder | |
| spss2csv <- function(filename) { | |
| data <- read.spss(filename, | |
| reencode='utf-8', | |
| use.value.labels = FALSE, | |
| to.data.frame = TRUE) | |
| outputcsv <- paste0(filename,".csv") | |
| write.csv2(data,outputcsv) | |
| } | |
| files <- list.files("Path where the SPSS files are present", | |
| pattern="*.sav", full.names = TRUE) | |
| lapply(files, spss2csv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment