问题:在R中使用bind_rows时出现向量大小问题。

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

Problems wirh vector size with bind rows in R

问题

我试图使用bind_rows合并两个大型数据框。

df <- bind_rows(df1, df2)

结果是R无法分配大小为n的向量。

我想这样做是因为我需要按照日期和id排序并将其导出为txt。

df <- df %>%
  arrange(date, id)

我该怎么办?

英文:

I am trying to merge two large data frames with bind_rows.

df&lt;-bind_rows(df1,df2)

The result is that R cannot allocate a vector of n size.

I want to do this because I need to arrange and export it in a txt.

df&lt;-df%&gt;%
arrange(date,id)

What can i do?

答案1

得分: 1

第一个要问的问题是这两个数据框有多大?它们有多少行?如果它们的大小在合理范围内,你可以尝试使用基本R中的rbind,我预计它的开销会比bind_rows小,但我不确定。

如果你的数据太大,无法由数据框处理,你应该考虑使用data.table数据类型或一种将数据存储在磁盘而不是内存中的方法。例如,可以参考以下参考链接:https://rdpeng.github.io/RProgDA/working-with-large-datasets.html

英文:

The first question to ask is how big are the 2 data frames? How many rows do they have? If it is something reasonable, one simple thing you could try is to use rbind from base R, which I expect to have less overhead than bind_rows, but I'm not sure about that.

If your data are too big to be handled by data frames, you should look into using the data.table data type or an approach where the data is stored on disk instead of memory. See for example the following reference: https://rdpeng.github.io/RProgDA/working-with-large-datasets.html

huangapple
  • 本文由 发表于 2023年5月28日 01:15:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348108.html
匿名

发表评论

匿名网友

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

确定