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]
This is pretty simple, if you know about the sign
function...
which(diff(sign(df))!=0)
# [1] 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With