Skip to content

Instantly share code, notes, and snippets.

@erinshellman
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erinshellman/6884edfa0a5dd78b5e57 to your computer and use it in GitHub Desktop.
Save erinshellman/6884edfa0a5dd78b5e57 to your computer and use it in GitHub Desktop.
Read in multiple, identically ordered files.
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