rmemoryffbigdata

how to make arithmatic operations in ffdf object of ff package


I have the script making a ffdf object:

library(ff)
library(ffbase)

setwd("D:/My_package/Personal/R/reading")
x<-cbind(rnorm(1:100000000),rnorm(1:100000000),1:100000000)
system.time(write.csv2(x,"test.csv",row.names=FALSE))

system.time(x <- read.csv2.ffdf(file="test.csv", header=TRUE,         first.rows=1000, next.rows=10000,levels=NULL)) 

Now I want to increase the column#1 of x by 5.
To perform such an operation I use method 'add()' of ff package:

add(x[,1],5)

The ouput is Ok (column#1 is increased by 5). But the extra RAM allocation is disasterous - it looks like as if I am operating the entire dataframe in RAM but not a ffdf object.

So my question is about the correct way to deal with elements of ffdf object without drastic extra RAM allocations.


Solution

  • You can just do as follows

    require(ffbase)
    
    x <- ff(1:10)
    y <- x + 5
    x
    y
    

    ffbase has worked out all the Arithmetic operations see help("+.ff_vector")