1

I am trying to read a big table (around 500000 x 1000) in R.

read.table works, but is horribly slow.

scan works, too, and is OK speedwise, but I have been unable to change its format to a normal data.frame or matrix.

I do not know the number of rows in the table in advance (I can find the number of columns by template_line <- read.table(nrow=1,file=my_file)). It needs to be compatible with R 2.15 - so it seem fread is out of the question.

So the question is either: How do I convert the output from:

my_matrix <- scan(file=my_file,what=template_line);  

to a data.frame or matrix (fast)?

Or: how do I read a table of integers fast in R if I do not know the size?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Ole Tange
  • 29,397
  • 5
  • 75
  • 92

1 Answers1

0

What about this?

num_cols <- 5
my_matrix <- matrix(scan(file=my_file, what=template_line), ncol=num_cols, byrow=TRUE)
user1578653
  • 4,688
  • 15
  • 43
  • 72