[R] a sequence that wraps around

Henrique Dallazuanna wwwhsd at gmail.com
Wed Sep 16 16:37:43 CEST 2009


Try rep:

rep(2:4, lenght.out = 3, times = 10)

On Wed, Sep 16, 2009 at 11:08 AM, Jack Tanner <ihok at hotmail.com> wrote:
> I'd like to have something like seq() where I can pass in a length of the
> desired sequence and a right limit so that the sequence goes up to the limit and
> then starts again from 1.
>
> # works now
> seq(from=2, length.out=3)
> [1] 2 3 4
>
> # what I want
> seq(from=2, length.out=3, rlimit=3)
> [1] 2 3 1
>
> # additional examples of what I want
> seq(from=2, length.out=4, rlimit=3)
> [1] 2 3 1 2
> seq(from=2, length.out=4, rlimit=4)
> [1] 2 3 4 1
> seq(from=2, length.out=3, rlimit=2)
> [1] 2 1 2
>
> I can write this procedurally, but it seems like there ought to be a cleaner R
> way of doing it. Thanks in advance for any suggestions.
>
> ______________________________________________
> R-help at 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list