Skip to content
Prev 247305 / 398503 Next

Selecting the first occurrence of a value after an occurrence of a different value

Hi,

 I'll do something like this (there is probably a nicer way, but this code
is what first comes up to my mind)

 provided your data is in x

 pos1 <- which(x %in% val1)[1]
 pos2  <- which(x %in% val2)[which(x %in% val2) >  pos1][1]