I have several different csv files with the same structure. I read them into R using fread, and then union them into a bigger dataset using rbindlist().
You are only missing the idcol argument from rbindlist(). Run:
x2csv <- rbindlist(lapply(files, fread, stringsAsFactors = FALSE), fill = TRUE, idcol = TRUE )
This is an enhanced version of Nicolás' answer which adds the file names instead of numbers:
x2csv <- rbindlist(lapply(files, fread), idcol = "origin")
x2csv[, origin := factor(origin, labels = basename(files))]
fread() uses stringsAsFactors = FALSE by default so we can save some keystrokesfill = TRUE is only required if we want to read files with differing structure, e.g., differing position, name, or number of columns.id) and is populated with the sequence number of the list element.basename() strips the path off the file name.