What is the findInterval() function in R?

Overview

The findInterval() function in R returns the indices or the index position of a number x in a given vector vec.

Syntax

findInterval(X, vec)
Syntax for the findInterval() function

Parameter value

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.

Example

# creating a increasingly sorted vector object
vec <- c(1, 2, 3, 4, 5, 10)
# implementing the findInterval() function to find the index position of 1
findInterval(1, vec)
# to find the index position of 5 in the vector object
findInterval(5, vec)
# to find the index position of 10 in the vector object
findInterval(10, vec)

Free Resources