英文:
In R , a question about dplyr::bind_rows combine dataframes
问题
有R中的数据框,名称类似于data_1 data_2 data_3 data_4 ....
,下面的代码尝试将它们组合在一起,但失败了。如何修复它?谢谢!
dplyr::bind_rows(ls(pattern = "data*"))
英文:
There are dataframes in R , which name like data_1 data_2 data_3 data_4 ....
, below code combine all of them failed . How to fixed it ? Thanks1
dplyr::bind_rows(ls(pattern = "data*"))
答案1
得分: 1
你可以尝试这样做:
dplyr::bind_rows(mget(ls(pattern = "data*"))
或者
data.table::rbindlist(mget(ls(pattern = "data*")))
我们只从ls(pattern = "data*")
中获取字符串,并需要使用mget
将这些字符串转换为对象。
英文:
You may want to try this:
dplyr::bind_rows(mget(ls(pattern = "data*")))
or
data.table::rbindlist(mget(ls(pattern = "data*")))
We only get strings from ls(pattern = "data*")
, and need to convert those strings to objects using mget
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论