I have many data.tables in memory with names following a specific pattern (e.g.: RE_1, RE_2... CO_1, CO_2...). I want to bind them efficiently to get only two data.tables (RE and CO).
I tried:
RE <- rbindlist(ls(pattern = "RE"))
But I got the following error: "Error in rbindlist(ls(pattern = "RE")) : Input to rbindlist must be a list of data.tables".
Is there a way to make such a "usable" list of data.tables (or data frames)?
tables
, otherwise you will be picking everything that matches RE from the global environment, including lists, data frames and etc. In other words, the correct way of doing this istemp <- tables(mb = FALSE, silent = TRUE)$NAME; rbindlist(mget(grep("RE", temp, value = TRUE))); rbindlist(mget(grep("CO", temp, value = TRUE)))
- David Arenburgdata.table
s from your environment. - David Arenburgrbindlist(lapply(file_names_RE,fread))
- MichaelChirico