列出内存中的data.tables并按行合并(rbind) [英] list data.tables in memory and combine by row (rbind)

查看:56
本文介绍了列出内存中的data.tables并按行合并(rbind)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的内存中有很多data.table,它们的名称遵循特定的模式(例如: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.table(或数据帧)列表?

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本身。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆