x <- c(1:4, 0:5, 11)
which.min(x)
which.max(x)
## it *does* work with NA's present, by discarding them:
presidents[1:30]
range(presidents, na.rm = TRUE)
which.min(presidents) # 28
which.max(presidents) # 2
## Find the first occurrence, i.e. the first TRUE:
x <- rpois(10000, lambda = 10); x[sample.int(50, 20)] <- NA
## where is the first value >= 20 ?
which.max(x >= 20)
Run the code above in your browser using DataLab