Finding the index of first changes in the elements of a vector

r

Solution

`rle` is a good idea, but if you only want the indices of the changepoints you can just do:

c(1,1+which(diff(v)!=0))
## 1 8 10

Problem

I have a vector `v` and I would like to find the index of first changes in elements of a vector in R. How can I do this? For example: ``` v = c(1, 1, 1, 1, 1, 1, 1, 1.5, 1.5, 2, 2, 2, 2, 2) ```

Original source