Сначала сделайте небольшой пример, который вычисляет в R:
x<- c(1,3,1,4,2)
max(which(x<2))
[1] 3
Теперь я хотел бы сделать это не только для одного значения 2, но и для многих значений одновременно. Это должно дать мне что-то вроде этого:
max(which(x<c(1,2,3,4,5,6)))
[1] NA 3 5 5 5 5
Конечно, я мог бы запустить цикл for
, но это очень медленно:
for(i in c(1,2,3,4,5,6)){
test[i]<-max(which(x<i))
}
Есть ли быстрый способ сделать это?