Check if a numeric value falls between a range in R Programming - between() function - GeeksforGeeks (2024)

  • Read

  • Improve

    Improve

    Improve

    Like Article

    Like

    Save Article

    Save

    Report issue

    Report

    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 package

    install.packages("dplyr")

    # Load dplyr package

    library("dplyr")

    # Define value

    x1 <- 7

    # Define lower bound

    left1 <- 1

    # Define upper bound

    right1 <- 10

    # Apply between function

    between(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 package

    install.packages("dplyr")

    # Load dplyr package

    library("dplyr")

    # Define value

    x2 <- 11

    # Define lower range

    left2 <- 1

    # Define upper range

    right2 <- 10

    # Apply between function

    between(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.


    Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!


    Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.

    Last Updated : 26 May, 2020

    Like Article

    Save Article

    Share your thoughts in the comments

    Please Login to comment...

    Check if a numeric value falls between a range in R Programming - between() function - GeeksforGeeks (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Jamar Nader

    Last Updated:

    Views: 5662

    Rating: 4.4 / 5 (55 voted)

    Reviews: 94% of readers found this page helpful

    Author information

    Name: Jamar Nader

    Birthday: 1995-02-28

    Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

    Phone: +9958384818317

    Job: IT Representative

    Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

    Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.