【发布时间】:2016-03-04 02:33:17
【问题描述】:
我有两个数据框,每个都有 120 万行。
我尝试将它们与dummy <- merge(df1, df2) 合并。两个数据框都没有共同的列,但两个数据框的行都按我想要的顺序排列。
我希望它们并排合并,但是当我运行合并功能时,我得到了这个错误:
Error: cannot allocate vector of size 5905.6 Gb
In addition: Warning messages:
1: In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
Reached total allocation of 8107Mb: see help(memory.size)
2: In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
Reached total allocation of 8107Mb: see help(memory.size)
3: In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
Reached total allocation of 8107Mb: see help(memory.size)
4: In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
Reached total allocation of 8107Mb: see help(memory.size)
【问题讨论】:
-
什么是
object.size(df1)和object.size(df2) -
(120 万行告诉我你应该使用
data.table,顺便说一句......) -
“并排合并”:5905.6 Gb。真的没有希望完成这项工作。我怀疑您正在合并少量列,并且有很多重复值。对于两个数据集中重复值的每个组合,笛卡尔连接中有 N x M 个匹配项。请重新考虑您的方法。如果“并排”表示“逐行”,那么您需要
cbind,而不是merge。问题应该是dim(df1)和dim(df2)是什么。 -
矩阵和 data.frames 都有 cbind 方法。将
cbind与数据帧一起使用并没有特别危险,这类似于在数据帧上使用apply的危险。不会发生对“矩阵”类的强制。对于可以确保“并行数据”的情况,有一个merge( , , by="row.names")。) -
@MichaelChirico 你完全正确。其他阅读本文的人必须小心。就我而言,我肯定知道两个数据集中的行排成一行。我希望我能说更多关于我是如何知道的,但我不能。