R identifying a row prior to a change in sign

r

Solution

This is pretty simple, if you know about the `sign` function...

which(diff(sign(df))!=0)
# [1] 2

Problem

I have a vector: ``` df <- c(5,9,-8,-7,-1) ``` How can I identify the position prior to a change in sign? ie `df[2]`

Original source