Re: [R] generating a sequence

About this list Date view Thread view Subject view Author view

Peter Dalgaard BSA (p.dalgaard@biostat.ku.dk)
21 Dec 1999 23:19:44 +0100



"Jens Oehlschlägel-Akiyoshi" <jens.oehlschlaegel-akiyoshi@mdfactory.de> writes:

> As this looks like a funny performance competition,
> here a very tricky algorithm I once received from Angelo Canty
>
> vecseq <- function(x,y=NULL) {
> # x1:y1,x2:y2 ... Angelo Canty 8/97
> # parameter handling (c) JOA 1997
> if (missing(y)) {y <- x; x <- 1}
> if (length(y)==1) y <- rep(y,length(x))
> if (length(x)==1) x <- rep(x,length(y))
> str <- paste("c(",paste(x,y,sep=":",collapse=","),")")
> eval(parse(text=str))
> }
....
> So, vecsec() is more flexible and much faster than R's sequence,
> why not redefine sequence ?
> (timings on PII 400 NT4.0)

Hmm. vecseq is certainly impressively fast, but I tend to find any
routine that involves parsing suspicious.

sequence<-function(nvec)unlist(lapply(nvec,function(x)1:x))

clocks in at 0.09 (if you gc() first) and would seem to be equivalent
to the current one. Still two times slower than vecseq, though...

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Tue 04 Jan 2000 - 13:34:03 EST