[R] sequence that counts up and back down

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Fri Feb 6 08:52:29 CET 2009


one way is the following:

5 - abs(-4:4)


I hope it helps.

Best,
Dimitris

Monte Milanuk wrote:
> I hit a minor sticking point working one of the problems in 'Using R' 
> (Verzani).  I'm having difficulty with generating a sequence that goes 
> 1, 2, 3, 4, 5, 4, 3, 2, 1.  I can make one that counts up, I can make 
> one that counts down, etc. but one that counts up then down like this 
> (short of just using c() ) is stumping me.
> 
> Any help (on or off list) would be appreciated.
> 
> Thanks,
> 
> Monte
> 
> ______________________________________________
> 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.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014




More information about the R-help mailing list