On Tue, Jan 25, 2011 at 08:58:31AM +0000, Prof Brian Ripley wrote: [...] > >If k may be 0, then it is better to use > > > > for (n in seq(length=k)) > > > >since seq(length=0) has length 0. > > Since you keep mentioning that, it is actually much better to use > seq_len(k) (and seq_along(x) instead of your earlier recommendation of > seq(along=x)). And if you are using seq() in other cases in programs, > consider seq.int() instead.
Thank you for pointing out the functions seq_len(), seq_along() and seq.int(). These functions are primitive and faster, as others already mentioned. Using replicate(), i obtained on my computer a speed up by a factor between 5 and 7 for k <= 20 and there is a remarkable speed up also for larger k. The function seq.int() is more general than the other two. In particular, it can generate also a decreasing sequence. Petr Savicky. ______________________________________________ R-help@r-project.org 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.