[R] Successive subsets from a vector?
hadley wickham
h.wickham at gmail.com
Tue Aug 22 14:37:38 CEST 2006
> 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
More information about the R-help
mailing list