2016-03-04 29 views
1

我有兩個數據幀,每個數據幀有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) 
+0

什麼是'object.size(DF1)'和'object.size(DF2)'' – MichaelChirico

+0

15113968 bytes'和'215909312個字節'@MichaelChirico – Username

+0

你想要做什麼樣的合併? http://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right – MichaelChirico

回答

1

你可能想嘗試data.table::cbind一個通過引用替代合併上row.names

library("data.table") 
setDT(df1) 
setDT(df2) 
data.table::cbind(df1, df2) 

但要注意在包裝reference這樣的警告:

These functions are masked in data.table because of this feature in cbind :

「The data frame method will be used if at least one argument is a data frame」. This means that cbind(DT,DF) dispatches to the S3 method cbind.data.frame even when cbind.data.table is provided by data.table. Therefore, we have masked these functions. Warning messages will be presented to the user (by R) when the data.table package is loaded. If the first argument is not a data.table, then they revert to the base versions.

+0

根據數據的結構和密度,您也可以將這些數據幀轉換爲稀疏矩陣並使用類似[cBind](http://www.inside-r.org/r-doc/Matrix/cBind ) – C8H10N4O2