Re: [R] jump in sequence

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Tue 30 Jan 2007 - 15:05:18 GMT

 > f <- function(n){as.vector(sweep(matrix(4:6,nrow=3,ncol=n),2,seq (from=0,by=9,len=n),"+"))}
 > f(10)
[1] 4 5 6 13 14 15 22 23 24 31 32 33 40 41 42 49 50 51 58 59 60 67 68 69 76 77 78 85 86 87
 >

HTH rksh

On 30 Jan 2007, at 14:29, 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
>
> --
> Adrian Dusa
> Romanian Social Data Archive
> 1, Schitu Magureanu Bd
> 050025 Bucharest sector 5
> Romania
> Tel./Fax: +40 21 3126618 \
> +40 21 3120210 / int.101
>
> ______________________________________________
> 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.

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
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 Wed Jan 31 02:23:07 2007

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 Tue 30 Jan 2007 - 16:30:27 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.