Find position of first value greater than X in a vector

curbholes picture curbholes · Apr 1, 2015 · Viewed 47.2k times · Source

In R: I have a vector and want to find the position of the first value that is greater than 100.

Answer

Phil picture Phil · Apr 1, 2015
# Randomly generate a suitable vector
set.seed(0)
v <- sample(50:150, size = 50, replace = TRUE)

min(which(v > 100))