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 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 obtain an vector that indicates the position
of the changing element of "a"?
In this case it would be something like:

index<-c(1,6,9,12,14,15)

usually I'm used cycles to obtain boolean vectors of the same length of "a"
indicating the changing elements ...later I've muliplied them for their
numeric sequence and after that I've selected elements different from zero
...it is quite long...
can you find an easier solution?

Thank you for you help
-- 
View this message in context:
http://r.789695.n4.nabble.com/switching-elements-of-a-vector-tp2228373p22283
73.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@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.

______________________________________________
R-help@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.

Reply via email to