[R] Selecting the first occurrence of a value after an occurrence of a different value

Taras Zakharko taras.zakharko at gmail.com
Fri Jan 14 10:57:45 CET 2011


 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]

View this message in context: http://r.789695.n4.nabble.com/Selecting-the-first-occurrence-of-a-value-after-an-occurrence-of-a-different-value-tp3217340p3217385.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list