> The loop method took 195 secs.  Just assigning to an answer of the correct
> length reduced this to 5 secs.  e.g. use
>
>     ADDRESSES <- character(length(VECTOR)-4)
>
> Moral: don't grow vectors repeatedly.

Other languages (eg. Java) grow the size of the vector independently
of the number of observations in it (I think Java doubles the size
whenever the vector is filled), thus changing O(n) behaviour to O(log
n).  I've always wondered why R doesn't do this.

Hadley

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to