[R] rbind and data.frame [simplified]

Göran Broström gb at stat.umu.se
Mon Dec 10 11:09:48 CET 2001


On 10 Dec 2001, Peter Dalgaard BSA wrote:

> Göran Broström <gb at stat.umu.se> writes:
> 
> > Thanks for the interest in my timing problem. I have scaled off all 
> > calculations in order to purify it, and it is obvious that size 
> > matters a lot. Also that 'matrices are faster than data frames'.
> > 
> > I give you the full listing here, but it is 
> > really the last few lines that are interesting (= slow):
> 
> ...
> >   for (cur.row in (1:no.of.outrows)){
> >     dat.out[cur.row, ] <- fixed.rec
> >       ## cbind(fixed.rec, com.dat[1, , drop = FALSE])
> >     ## cat("row = ", cur.row, "\n")
> >   }
> >   ## return(dat.out)
> > }
> > ------------------------------------------------------------------------
> ...,
> > Sens moral: Avoid data frames for manipulations of this kind.
> > (Am I right?)
> 
> Hmm. With 1.4.0 on the immediate horizon I don't want to go into
> actually trying to run this stuff, but it wouldn't be the first time
> that data frame code caused slowness by ensuring that the
> result of operations is a data frame every single step of the way.
> 
> What happens if you do do something like this?: Replace the
>   dat.out[cur.row, ] <- fixed.rec
> with 
>   for (i in 1:ncol) dat.out[[i]][cur.row] <- fixed.rec[[i]]
> 
> bypassing "[<-.data.frame"
> 

Timing stopped at: 529.27 122.76 668.1 0 0

i.e. catastrophic! I hadn't time to wait; this was with writing 100
records.

Göran
-- 
 Göran Broström                      tel: +46 90 786 5223
 professor                           fax: +46 90 786 6614
 Department of Statistics            http://www.stat.umu.se/egna/gb/
 Umeå University
 SE-90187 Umeå, Sweden             e-mail: gb at stat.umu.se

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list