The findInterval()
function in R returns the indices or the index position of a number x
in a given vector vec
.
findInterval(X, vec)
The findInterval()
function takes the following parameter values:
x
: This represents the number to be searched.vec
: This is the numeric vector object sorted increasingly.# creating a increasingly sorted vector objectvec <- c(1, 2, 3, 4, 5, 10)# implementing the findInterval() function to find the index position of 1findInterval(1, vec)# to find the index position of 5 in the vector objectfindInterval(5, vec)# to find the index position of 10 in the vector objectfindInterval(10, vec)