List of lists? Data frames? (Or other data structures?)
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:
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.
From: "R A F" <raf1729 at hotmail.com> To: p.dalgaard at biostat.ku.dk CC: r-help at stat.math.ethz.ch, rpeng at stat.ucla.edu, ripley at stats.ox.ac.uk Subject: Re: [R] List of lists? Data frames? (Or other data structures?) Date: Thu, 01 May 2003 12:20:57 +0000 Ah, thanks! (It's not that I didn't reading it -- I didn't understand it and so I thought that it'd be easier to ask again. Thanks very much!)
From: Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> To: "R A F" <raf1729 at hotmail.com> CC: ripley at stats.ox.ac.uk, rpeng at stat.ucla.edu, r-help at stat.math.ethz.ch Subject: Re: [R] List of lists? Data frames? (Or other data structures?) Date: 01 May 2003 14:19:32 +0200 You're not taking Brian's hint!:
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help