Re: [R] List of lists? Data frames? (Or other data structures?)

About this list Date view Thread view Subject view Author view Attachment view

From: Aleksey Naumov (naumov@buffalo.edu)
Date: Fri 02 May 2003 - 01:38:07 EST


Message-id: <Pine.GSO.4.05.10305011129260.14165-100000@hercules.acsu.buffalo.edu>


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@hotmail.com>
> >To: p.dalgaard@biostat.ku.dk
> >CC: r-help@stat.math.ethz.ch, rpeng@stat.ucla.edu, ripley@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@biostat.ku.dk>
> >>To: "R A F" <raf1729@hotmail.com>
> >>CC: ripley@stats.ox.ac.uk, rpeng@stat.ucla.edu, r-help@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@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Tue 01 Jul 2003 - 09:11:44 EST