1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2120870
  • 869
  • 4
  • 16
  • 1
    I have not tested this, but it seems that `read.table.ffdf`is calling `read.table`, and that it is possible to send parameters to `read.table`. For `read.table` you can skip a column by setting `"NULL"` in `colClasses`. Something like `read.table.ffdf("file.txt", header=T, sep="\t", colClasses=c("NULL", "character", "character"))` might do the trick. – DGKarlsson Sep 23 '15 at 12:58

1 Answers1

1

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
LyzandeR
  • 37,047
  • 12
  • 77
  • 87