Skip to content

List of lists? Data frames? (Or other data structures?)

2 messages · R A F, Aleksey Naumov

#
For what it's worth, I followed the suggestion of using colClasses:

cls <- c( "numeric", "character", "numeric", "numeric", "numeric" )
system.time( bbb <- read.table( "file", colClasses = cls ) )

Here're the results from three tries:
8.21 0.06 8.28 0.00 0.00
8.94 0.10 9.10 0.00 0.00
8.55 0.06 8.69 0.00 0.00

I also did
system.time( aaa <- scan( "file", list( 0, "", 0, 0, 0 ) ) three
times:

6.46 0.04 6.59 0.00 0.00
5.27 0.04 5.33 0.00 0.00
5.14 0.05 5.19 0.00 0.00

By the way, I did the experiment in the order bbb, aaa, bbb, aaa,
bbb, aaa.

So it appears that read.table is still a little slower -- but it could
be just me doing something wrong.

Thanks.
#
Try str(aaa) after running scan() and read.table():

scan() returns a list of vectors, while read.table() returns a data frame.
The extra time taken by read.table() (in my tries read.table is 1.2-1.5
times slower than scan, consistent with your numbers) must be due to
binding the vectors into a data frame (checking that they have the same
length, etc). 
In my runs trying to convert the result of scan() into a data frame (with
as.data.frame(aaa)) took about the same time as read.table(), so if you
want a data frame in the end, read.table() may be best.

Aleksey
On Thu, 1 May 2003, R A F wrote: