Let\'s make a small example first, that computes in R:
x<- c(1,3,1,4,2) max(which(x<2)) [1] 3
Now, I would like to do this not just for