# [R] how to make this sequence: 1,2,3,4,5,4,3,2,1

kMan kchamberln at gmail.com
Sat Mar 6 04:30:59 CET 2010

```c(x,(x<-1:5)[4:1])

-----Original Message-----
From: baptiste auguie [mailto:baptiste.auguie at googlemail.com]
Sent: Friday, March 05, 2010 1:08 AM
To: kensuguro
Cc: r-help at r-project.org
Subject: Re: [R] how to make this sequence: 1,2,3,4,5,4,3,2,1

c(x <- 1:5, rev(x[-length(x)]))

On 5 March 2010 07:04, kensuguro <magronbass at gmail.com> wrote:
>
> I'm just beginning R, with book Using R for Introductory Statistics,
> and one of the early questions has me baffled.  The question is,
> create the
> sequence: 1,2,3,4,5,4,3,2,1 using seq() and rep().
>
> Now, as a programmer, I am punching myself to not be able to figure it
out..
> I mean, as simple as a for loop, but using seq, I am stumped.  I would
> think c(1:5, 4:1) would be the brute force method with very non
> intelligent coding..  there has to be a way to make the "turning
> point" (in this case 5) parametric right?  So you could change it
> later and the sequence will reflect it.
> --
> View this message in context:
> http://n4.nabble.com/how-to-make-this-sequence-1-2-3-4-5-4-3-2-1-tp157
> 9245p1579245.html Sent from the R help mailing list archive at
> Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
____________________

Baptiste Auguié

Departamento de Química Física,