简体   繁体   English

在R中合并ffdf数据帧

[英]Merging ffdf dataframes in R

I need an outer join of ffdf dataframes saved in a list. 我需要一个保存在列表中的ffdf数据帧的外部联接。 Have checked this , but it refers to a different problem. 已经检查了这个 ,但是它指的是另一个问题。 Example code for RAM objects: RAM对象的示例代码:

x1 = data.frame(name='a1', Ai=2, Ac=1, Bi=1)
x2 = data.frame(name='a2', Ai=1, Bi=3, Bc=1, Ci=1)
x3 = data.frame(name='a3', Ai=3, Ac=2, Bi=2, Ci=3, Cc=1, Di=2, Dc=2)
x4 = data.frame(name='a4', Ai=3, Bi=2, Ci=1, Fi=2)
dl = list(x1,x2,x3,x4)
mergedDF = Reduce(function(...) merge(..., all=T), dl)
mergedDF[is.na(merged.data.frame)] = 0

Desired result looks like: 所需结果如下:

mergedDF
  name Ai Bi Ci Ac Bc Cc Di Dc Fi
1   a1  2  1  0  1  0  0  0  0  0
2   a2  1  3  1  0  1  0  0  0  0
3   a3  3  2  3  2  0  1  2  2  0
4   a4  3  2  1  0  0  0  0  0  2

As long as I turn the data frames to ffdf though, I get the error 只要我将数据帧转到ffdf,我就会收到错误消息

Error in merge.ffdf(..., all = T) : merge.ffdf only allows inner joins

Any known workrounds? 任何已知的工作回合? Many thanks in advance. 提前谢谢了。

This post helped me Combine two data frames by rows (rbind) when they have different sets of columns . 这篇文章帮助我在两个数据帧具有不同的列集时按行组合(rbind) So to do a similar thing with yours: 因此,对您的人做类似的事情:

   install.packages('plyr')
   require(plyr)
   answer <- Reduce(rbind.fill,dl)
   answer[is.na(answer)] <- 0
   answer

  name Ai Ac Bi Bc Ci Cc Di Dc Fi
1   a1  2  1  1  0  0  0  0  0  0
2   a2  1  0  3  1  1  0  0  0  0
3   a3  3  2  2  0  3  1  2  2  0
4   a4  3  0  2  0  1  0  0  0  2

BTW nice thought with Reduce , that's a nifty little function that rarely (at least for me) gets used. 顺便说一下, Reduce是一个不错的小功能,很少(至少对我来说)不被使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM