# Test whether a numeric value falls into a specified range in R

Test whether a numeric value falls into a specified range in R, Let’s dive into the problem.

## Example 1: Interactions between Basic Function

The dplyr package from the tidyverse must first be loaded and installed if we want to use the between() function:

#install.packages("dplyr") library("dplyr")

Following that, we must also define a value, an upper bound, and a lower bound for our range.

**Test whether a numeric value falls into a specified range in R**

Best Data Science Algorithms » finnstats

x1 <- 5 a <- 3 b <- 8

Now that we have our values, we can use the between the function to see if they fall within our range:

between(x1, a, b) TRUE

Our result exceeds both the lower and higher bounds, as shown by the RStudio console returning the logical value TRUE.

## Example 2. Value Outside of Range

Let’s give an example of what occurs when a value is checked that is outside of our range. To start, we must define a few new values.

x2 <- 100 a <- 12 b <- 17

As we did in Example 1, we can now use the between command.

Where can I find Data Science Internships » finnstats

between(x2, a, b) FALSE

This time, the between function informs the RStudio console that our value does not fall within our range by returning FALSE.