英文:
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<-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<-df%>%
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论