between() function in R Language is used to check that whether a numeric value falls in a specific range or not.
A lower bound and an upper bound is specified and checked if the value falls in it.
Syntax: between(x, left, right)
Parameters:
x: A numeric vector
left, right: Boundary values
Example 1: Values in Range
# R program to illustrate# between function # Install dplyr packageinstall.packages("dplyr") # Load dplyr package library("dplyr") # Define valuex1 <- 7 # Define lower bound left1 <- 1 # Define upper bound right1 <- 10 # Apply between functionbetween(x1, left1, right1) |
Output:
TRUE
Here in the above code, we have defined value to 7 to x1 and defined upper and lower bound 1 and 10 respectively.
As we have given the value 7 falls in range 1 to 10. So the Output is “TRUE”.
Example 2: Value not in Range
# R program to illustrate# between function # Install dplyr packageinstall.packages("dplyr") # Load dplyr package library("dplyr") # Define valuex2 <- 11 # Define lower range left2 <- 1 # Define upper range right2 <- 10 # Apply between functionbetween(x2, left2, right2) |
Output:
FALSE
Here in the above code, we have assigned a value 11 to x2 and defined upper and lower bound to 1 and 10 respectively.
And clearly the value 11 does not fall in a given range from 1 to 10.
So the answer is FALSE.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.


