Last active
October 23, 2019 12:45
-
-
Save egeulgen/48b10331eb85791285cae9a08f279557 to your computer and use it in GitHub Desktop.
Merges multiple files into a single dataframe
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
multimerge <- function(mypath){ | |
filenames <- list.files(path=mypath, full.names=TRUE) | |
datalist <- lapply(filenames, function(x) read.csv(file=x,header=T)) | |
result_df <- Reduce(function(x,y) merge(x,y), datalist) | |
return(result_df) | |
} | |
### Cleaner and faster | |
# import files | |
files <- list.files(pattern="*.csv") | |
dataset <- do.call(rbind, lapply(files, data.table::fread)) | |
# transform data to df | |
dataset <- as.data.frame(unclass(dataset)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment