Re: [R] switching elements of a vector

2010-05-24 Thread Bert Gunter
AM To: r-help@r-project.org Subject: [R] switching elements of a vector 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 o

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 https://stat.ethz.ch/m

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: http://r.789695.n4.nabble.com/switching-elements-of-a-vector-tp2228373p2

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 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,

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 increasin

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 indicate

[R] switching elements of a vector

2010-05-24 Thread speretti
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 position of the changing element of "a"? In this ca