[R] Recursive decreasing sequences

Marc Schwartz MSchwartz at mn.rr.com
Fri Oct 20 22:16:12 CEST 2006


On Fri, 2006-10-20 at 15:11 -0500, Marc Schwartz wrote:
> On Fri, 2006-10-20 at 12:51 -0700, Julian Burgos wrote:
> > Hello fellow R's,
> > 
> > I'm sure there must be an easy way to do this.  But after digging in the 
> > documentation and thinking about it for a while I couldn't figure it 
> > out.  I need to get a decreasing recursive vector in.  I mean something 
> > like this: if starting at 2, and ending at 6, the vector should be
> > 
> >  2 3 4 5 6 3 4 5 6 4 5 6 5 6 6
> > 
> > An easy way would be to do this
> > 
> >     x <- integer(0)
> >     for (i in 5) x <- c(x, i:5)
> > 
> > But I need to create really long vectors (where the ending value is in 
> > the order of 6500) , and using loops is way to slow.  I'm looking for a 
> > vectorized method.  Any help will be welcomed.
> 
> How about this:
> 
> Range <- c(2:6)

Gack....

Disregard the 'c' and parens there.  Left over from a first attempt at a
solution using c(2, 6)...

Marc



More information about the R-help mailing list