[R] rbind and data.frame [simplified]

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Dec 10 10:27:11 CET 2001


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"
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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