Last active
August 29, 2015 14:16
-
-
Save erinshellman/6884edfa0a5dd78b5e57 to your computer and use it in GitHub Desktop.
Read in multiple, identically ordered files.
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
multiread.delim = function(path, header = TRUE, sep = '\t') { | |
# multiread.delim is a function to read in all the files in a given directory | |
# and rbind them into one data frame. Input files need to be of the same | |
# structure. Headers will be labeled according to the headers in the first file. | |
file_names = paste(path, list.files(path), sep = '/') | |
for (file in file_names) { | |
if (!exists('combined_df')) { | |
dataset = read.delim(file, header = header, sep = sep) | |
names(dataset) = clean_strings(names(dataset)) | |
} | |
if (exists('combined_df')) { | |
temp = read.delim(file, header = header, sep = sep) | |
names(temp) = names(combined_df) | |
combined_df = rbind(combined_df, temp) | |
rm(temp) | |
} | |
} | |
return(dataset) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment