[R] Recursive decreasing sequences

From: Julian Burgos <jmburgos_at_u.washington.edu>
Date: Fri 20 Oct 2006 - 19:51:58 GMT


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.

Julian

Julian M. Burgos

Fisheries Acoustics Research Lab
School of Aquatic and Fishery Science
University of Washington

1122 NE Boat Street
Seattle, WA 98105

Phone: 206-221-6864



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. Received on Sat Oct 21 12:32:47 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 21 Oct 2006 - 03:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.