1 | initial version |
The multmerge()
function is not a built-in function in R. However, a custom function could be created to combine files in a directory using the following general process:
list.files()
functiongrep()
functionread.csv()
, read.table()
)rbind()
or cbind()
)write.csv()
, write.table()
)Here is an example function that could combine csv files in a directory:
multmerge <- function(dir_path, file_ext){
# get file names in directory
files <- list.files(dir_path)
# filter to only include desired file extension
files <- files[grep(file_ext, files)]
# create empty data frame to store combined data
combined_data <- data.frame()
# iterate through each file and combine with previous data
for (file in files){
file_path <- paste0(dir_path, "/", file)
file_data <- read.csv(file_path)
combined_data <- rbind(combined_data, file_data)
}
# return combined data
return(combined_data)
}
This function could be called with the desired directory path and file extension:
combined_data <- multmerge("/path/to/directory", ".csv")