Created
March 21, 2019 19:22
-
-
Save narath/9c5d09e5681e741999d253235849d8d3 to your computer and use it in GitHub Desktop.
R code to read all the csv files into a single dataset (only works when all csv files have the same format)
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
read_all_csv_files <- function(dir) { | |
save_dir <- getwd() | |
setwd(dir) | |
files <- list.files(pattern = "csv") | |
for (file in files) { | |
if (!exists("dataset")){ | |
dataset <- read.csv(file) | |
} else { | |
temp_dataset <- read.csv(file, stringsAsFactors = FALSE) | |
dataset <- rbind(dataset, temp_dataset) | |
rm(temp_dataset) | |
} | |
} | |
setwd(save_dir) | |
return(dataset) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment