Re: [R] switching elements of a vector

2010-05-24 Thread Chuck Cleland
On 5/24/2010 6:02 AM, speretti wrote: Hi, I would like to receive help for the following matter: If I'm dealing with a numeric vectors containing increasing elements. i.e. a-c(1,2,2,2,2,3,3,3,4,4,4,5,5,6,7,7,7) There exist an efficient way to obtain an vector that indicates the

Re: [R] switching elements of a vector

2010-05-24 Thread schuster
Hi, is this what you need? b - c(NA, a[1:length(a)-1]) # shift values of a one step to the right which(a-b == 1) On Monday 24 May 2010 12:02:55 pm speretti wrote: Hi, I would like to receive help for the following matter: If I'm dealing with a numeric vectors containing increasing

Re: [R] switching elements of a vector

2010-05-24 Thread Gabor Grothendieck
Try this: which(diff(a) 0) + 1 [1] 2 6 9 12 14 15 On Mon, May 24, 2010 at 6:02 AM, speretti sabrina.pere...@gmail.com wrote: Hi, I would like to receive help for the following matter: If I'm dealing with a numeric vectors containing increasing elements. i.e.

Re: [R] switching elements of a vector

2010-05-24 Thread speretti
Thank you ! Great answers...now it seems very easy... As usual...a the obviousness of a solution depends on how you face the problem... Thank you for help me in find the good approaches... -- View this message in context:

Re: [R] switching elements of a vector

2010-05-24 Thread speretti
it works as well! -- View this message in context: http://r.789695.n4.nabble.com/switching-elements-of-a-vector-tp2228373p2228485.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] switching elements of a vector

2010-05-24 Thread Bert Gunter
And, just for kicks, a yet another (somewhat inefficient)solution: match(unique(a),a) Cheers, Bert Gunter Genentech Nonclinical Statistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of speretti Sent: Monday, May 24, 2010 3:03