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 one value 2, but for many values simultaneously. It should give me something like that:

max(which(x<c(1,2,3,4,5,6))) [1] NA 3 5 5 5 5

Of course I could run a for loop, but that is very slow:

for(i in c(1,2,3,4,5,6)){ test[i]<-max(which(x<i)) }

Is there a fast way to do this?