I have a 8 x n matrix, for instance
set.seed(12345) m <- matrix(sample(1:50, 800, replace=T), ncol=8) head(m) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8
Here's one way using sapply:
sapply
which(sapply(seq(nrow(m)-2), function(x) isTRUE(37 %in% m[x,] & which(10 == m[x+1,]) < which(29 == m[x+1,]) & 42 %in% m[x+2,])))
The result contains all row number where the sequence starts:
[1] 57