I am looking for a way to quickly read and merge a bunch of data files using data.table\'s fread and rbindlist functions. I think if fread could take a vector of files names
You could do datatablelist = lapply(list.files("my/data/directory/"), fread)
and then rbind the resulting list of data frames.
Although lapply
is cleaner than an explicit loop, your loop will work if you read the files directly into a list.
datatablelist = list()
for(i in 1:length(datafiles)){
datatablelist[[datafiles[i]]] = fread(datafiles[i])
}