I am trying to merge data from different .txt files (all files in the same directory) where file names are different but each file contains the same column names. Below is the script I am trying to use:
files <- dir("/PATH/") names <- grep(files, pattern = "AA.*_ss.txt$",value = TRUE) Data<- map(names, read.delim, stringsAsFactors = FALSE, check.names = FALSE, row.names = NULL) Merge <- bind_rows(Data) #is it correct? write.csv(Merge, "./Combined.csv", row.names = F)
I want to insert a column in my combined file where * (it is a number in my file name which is unique for each file) can be listed as a reference to show from which file these rows are taken. Need help with this, please.