> a<-c(1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1) > which( a==1 & c(TRUE, a[-length(a)]!=1) ) [1] 1 6 16 23 > which( a==0 & c(TRUE, a[-length(a)]!=0) ) [1] 4 12 18
Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Aug 6, 2014 at 7:12 PM, Johnnycz <[email protected]> wrote: > Hello,everybody, > I have a sequence,like > a<-c(1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1),how > to get the position of each first 1 and 0, that's to say, how to get > b<-c(1,6,16,23) for first 1 and d<-c(4,12,18) for first 0. > Many thanks! > Johnny > [[alternative HTML version deleted]] > > ______________________________________________ > [email protected] 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. ______________________________________________ [email protected] 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.

