[R] jump in sequence

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Jan 30 15:38:52 CET 2007


Adrian DUSA wrote:
> Dear list,
>
> This should be a simple one, I just cannot see it.
> I need to generate a sequence of the form:
> 4  5  6 13 14 15 22 23 24
>
> That is: starting with 4, make a 3 numbers sequence, jump 6, then another 3
> and so on.
> I can create a whole vector with:
> myvec <- rep(rep(c(F, T, F), rep(3, 3)), 3)
>
> Then see which are TRUE:
> which(myvec)
> [1]  4  5  6 13 14 15 22 23 24
>
>
> I'd like to avoid creating the whole vector if possible; for very large ones
> it can be time consuming. There should be a way to only create the proper
> indexes...
>
> Thanks for any hint,
> Adrian
>   
Is this it?

> as.vector(outer(0:2,seq(4,22,9),"+"))
[1]  4  5  6 13 14 15 22 23 24

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list