[R] Sequence generation
Greg Snow
Greg.Snow at imail.org
Sun Aug 30 02:13:39 CEST 2009
Or just use the 'each' argument to seq.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Barry Rowlingson
> Sent: Saturday, August 29, 2009 1:50 PM
> To: njhuang86
> Cc: r-help at r-project.org
> Subject: Re: [R] Sequence generation
>
> On Sat, Aug 29, 2009 at 8:14 PM, njhuang86<njhuang86 at yahoo.com> wrote:
> >
> > Hey guys,
> >
> > I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2,
> 3, 1,
> > 2, 3... with the '1, 2, 3' repeated over 10 times.
>
> rep(1:3,10) # rep repeats its first argument according to the number
> in its second argument
>
> > Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?
>
> The second argument can be a vector, so what you want here is:
>
> rep(1:3,c(3,3,3))
>
> but you can create the second vector here also using rep! Hence:
>
> rep(1:3,rep(3,3))
>
> Barry
>
> ______________________________________________
> 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.
More information about the R-help
mailing list