简体   繁体   中英

rbinding two ffdf data frames in R

Another question about the ff package. Is there a rbind equivalent function in the ff or ffbase package in R? I want to bind two ff data frames by rows. Can this be done in the ff package or are there other libraries that could help me?

use ffdfappend from version 0.6 of the ffbase package. The ffdfappend of version 0.5 was designed to append a data.frame to an ffdf, while the one from version 0.6 also allows appending an ffdf to an ffdf. You can install version 0.6 of that package by using the following R code:

download.file(url="http://fffunctions.googlecode.com/git-history/b6fa5617810e012e5d809d77a9a99dbb25c7e6dc/output/ffbase_0.6.tar.gz", destfile="ffbase_0.6.tar.gz")
install.packages("ffbase_0.6.tar.gz", repos=NULL)

如果fd1中没有新的因子级别,您可以将adjustvmode设置为FALSE ,如下所示。

vd<-ffdfappend(fd, fd1, adjustvmode=F)

rbind() works with ffdf objects as desired. For example:

df1 = as.ffdf(data.frame(A = 21:23, B = letters[1:3]))
df2 = as.ffdf(data.frame(A = 31:34, B = letters[11:14]))
df3 = as.ffdf(data.frame(A = 41:42, B = letters[21:22]))
rbind(df1, df2, df3)

Yields:

ffdf (all open) dim=c(9,2), dimorder=c(1,2) row.names=NULL
ffdf virtual mapping
PhysicalName VirtualVmode PhysicalVmode  AsIs VirtualIsMatrix PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol PhysicalIsOpen
A            A      integer       integer FALSE           FALSE            FALSE                 1                1               1           TRUE
B            B      integer       integer FALSE           FALSE            FALSE                 2                1               1           TRUE
ffdf data
   A  B
1 21 a 
2 22 b 
3 23 c 
4 31 k 
5 32 l 
6 33 m 
7 34 n 
8 41 u 
9 42 v 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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