Adding a column with character data to a ffdf

1.1k Views Asked by At

I've tried to add a Source column to my ffdf, but can't seem to get it to work... if it was a normal df I would simply write

mtcars$NewCol <- "AB" 

If I do this for the ffdf it returns an error

require(ff)
require(ffbase)

mtcarsff <- as.ffdf(mtcars) 
mtcars$NewCol <- "testname"

Error in `[[<-.ffdf`(`*tmp*`, i, value = "testname") : 
assigned value must be ff

Any Ideas?

1

There are 1 best solutions below

0
Miguel On BEST ANSWER

This should work:

mtcarsff$NewCol <- as.ff(
    rep(factor("AB"), times = nrow(mtcarsff))
)

Note that "AB" must be considered a factor, not a character.