rsubsetread.tableff

Drop columns from ff objects


I would like to drop a column from ff object:

Input file file.txt is tab delimited like that:

Col1  Col2  Col2
 x1    x1    x1
 x2    x2    x3
 x3    x4    xh

Then reading with ff package:

library(ff)
df <- read.table.ffdf("file.txt", header=T, sep="\t")

I would like to exclude the first column (or skip it when importing the file). With a normal dataframe or a matrix I would simple apply a comand like that:

df <- df[,-1]

However, in ffobjects does not work. Any ideas?


Solution

  • You can do it like this:

    Say you have a test ffdf object like this:

    #create a test ffdf object
    testdf <- as.ffdf(data.frame(a=runif(100), b=runif(100), c=runif(100)))
    

    In order to remove the first column i.e. column a you could do:

    testdf$a <- NULL
    

    And as you can see column a gets eliminated:

    > testdf
    ffdf (all open) dim=c(100,2), dimorder=c(1,2) row.names=NULL
    ffdf virtual mapping
      PhysicalName VirtualVmode PhysicalVmode  AsIs VirtualIsMatrix PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol PhysicalIsOpen
    b            b       double        double FALSE           FALSE            FALSE                 1                1               1           TRUE
    c            c       double        double FALSE           FALSE            FALSE                 2                1               1           TRUE
    ffdf data
                 b          c
    1   0.10627724 0.93927750
    2   0.29170912 0.96716656
    3   0.17588141 0.43387388
    4   0.69673704 0.39921435
    5   0.93715272 0.41446052
    6   0.87093269 0.10513608
    7   0.87827066 0.72423617