Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
r
communitycreator

What is the findInterval() function in R?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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)
Implementing the findInterval() function

RELATED TAGS

function
r
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring