I have a vector containing both positive and negative values. For example, something like
x = c(1,2,1,-2,-3,3,-4,5,1,1,-3)
And now I want to note the indices of the vector where the value changes from positive to negative or negative to positive. So, in the example above, I would like something index vector that looks something like this.
y=c(0,0,0,1,0,1,1,1,0,0,1)
I do this in R, so if possible, I would like to avoid using for-loops.
source
share