The “between” Function in R
Package: dplyr
Purpose: To determine if values fall within a specified range.
General Class: Data Manipulation
Required Argument(s):
x: The vector of values to be evaluated.
left: The left endpoint of the range.
right: The right endpoint of the range.
Notable Optional Arguments:
...: Additional arguments passed to the comparison operators.
Example (with Explanation):
# Load necessary packages
library(dplyr)
# Create a sample data frame
data <- data.frame(
ID = c(1, 2, 3, 4, 5),
value = c(10, 15, 20, 25, 30)
)
# Filter rows where 'value' falls between 15 and 25
result <- data %>%
filter(between(value, 15, 25))
# Display the result
print(result)In this example, the between function from the dplyr package is used to filter rows in the sample data frame data where the ‘value’ column falls between 15 and 25 inclusively. The result is a new data frame result containing only the rows that satisfy the specified range condition.