In R, 有关 dplyr::bind_rows 合并数据框的问题。

huangapple go评论133阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月24日 11:56:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552476.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定