I am trying to merge several csv files with the same columns in R. I tried the solution proposed in : Merging of multiple excel files in R and works perfectly. However, I would like to add an index column (row name) to identify which file each row corresponds to. I tried:
files <- list.files(pattern="*.csv")
require(purrr)
mainDF <- files %>% map_dfr(read.csv, row.names=files)
But I get the error:
Error in read.table(file = file, header = header, sep = sep, quote = quote, : invalid 'row.names' length
I would like to get a column similar to this, or ideally just the numbers e.g. 1, 2 etc
Any ideas?