简体   繁体   中英

from ffdf to regular dataframe

Is there a way to transform a ffdf into a normal dataframe? Assuming that the thing is small enough to fit in the ram.

for example:

library(ff)
library(ffbase)

data(trees)
Girth  <- ff(trees$Girth)
Height <- ff(trees$Height)
Volume <- ff(trees$Volume)
aktiv  <- ff(as.factor(sample(0:1,31,replace=T)))
#Create data frame with some added parameters.
data <- ffdf(Girth=Girth,Height=Height,Volume=Volume,aktiv=aktiv)
rm(Girth,Height,Volume,trees,aktiv)

aktiv <- subset.ffdf(data, data$aktiv== "1" )

and then convert aktiv to data frame and save the RData (sadly the person waiting the output don't want to learn how to work with the ff package, so I have no choise)

Thanks

Just use as.data.frame :

aktiv <- subset(as.data.frame(data), aktiv == 1)

   Girth Height Volume aktiv
2    8.6     65   10.3     1
7   11.0     66   15.6     1
9   11.1     80   22.6     1
12  11.4     76   21.0     1
13  11.4     76   21.4     1
15  12.0     75   19.1     1
17  12.9     85   33.8     1
20  13.8     64   24.9     1
21  14.0     78   34.5     1
23  14.5     74   36.3     1
26  17.3     81   55.4     1
27  17.5     82   55.7     1
28  17.9     80   58.3     1
31  20.6     87   77.0     1

From here you can easily use save or write.csv , eg:

save(aktiv, file="aktiv.RData")

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