列出内存中的 data.tables 并按行组合 (rbind) [英] list data.tables in memory and combine by row (rbind)
问题描述
我在内存中有许多 data.tables,其名称遵循特定模式(例如:RE_1、RE_2... CO_1、CO_2...).我想有效地绑定它们以仅获取两个 data.tables(RE 和 CO).
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).
我试过了:
RE <- rbindlist(ls(pattern = "RE"))
但我收到以下错误:rbindlist(ls(pattern = "RE")) 中的错误:rbindlist 的输入必须是 data.tables 的列表.
But I got the following error: "Error in rbindlist(ls(pattern = "RE")) : Input to rbindlist must be a list of data.tables".
有没有办法制作这样一个可用"的 data.tables(或数据框)列表?
Is there a way to make such a "usable" list of data.tables (or data frames)?
推荐答案
试试
rbindlist(lapply(ls(pattern = "RE"),get))
不知道这是否是最有效的方法,但是......它有效.
Dont know if this is the most effective way but... It works.
ls(...)
返回一个带有你的 data.tables 名称的向量.不是 data.tables 本身.get
按名称获取对象.
ls(...)
returns a vector with the names of your data.tables. Not the data.tables themself. get
gets you the object by name.
你也可以使用
rbindlist(mget(ls(pattern = "RE")))
这篇关于列出内存中的 data.tables 并按行组合 (rbind)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!