My question is confusing. But, this is what I would like to do: Let's say I have a 10 data file in my current directory such as data-01, data-02, data-03, data-04 till data-10. Each of these data file have few hundred rows with 4 fields. I would like to add new column name "ID" and keep its ID like 01 (for data file "data-01") for all the rows in that file.
Many thanks in advanced.
library(data.table); LF = list.files(pattern="csv$"); rbindlist(lapply(setNames(LF,LF), fread), idcol = "source")if the fields are the same across the files. This stacks the data and makes a "source" column containing the file name associated with each row.