Check if the elements of a Vector are Finite, Infinite or NaN values in R Programming - is.finite(), is.infinite() and is.nan() Function - GeeksforGeeks (2024)

  • Read

  • Improve

    Improve

    Improve

    Like Article

    Like

    Save Article

    Save

    Report issue

    Report

    is.finite() function in R Language is used to check if the elements of a vector are Finite values or not. It returns a boolean value for all the elements of the vector.

    Syntax: is.finite(x)

    Parameters:
    x: Vector to be checked

    Example:

    # R program to illustrate

    # the use of is.finite() function

    # Creating a vector

    x <- c(1, 2, 3, 4, 5, NA, 6, 7)

    # Calling is.finite() function

    is.finite(x)

    Output:

    [1] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE

    is.infinite() Function

    is.infinite() Function in R Language is used to check if the vector contains infinite values as elements. It returns a boolean value for all the elements of the vector.

    Syntax: is.infinite(x)

    Parameters:
    x: Vector to be checked

    Example:

    # R program to illustrate

    # the use of is.infinite() function

    # Creating a vector

    x <- c(1, 2, Inf, 4, -Inf, 6)

    # Calling is.infinite() function

    is.infinite(x)

    Output:

    [1] FALSE FALSE TRUE FALSE TRUE FALSE

    is.nan() Function

    is.nan() Function in R Language is used to check if the vector contains any NaN(Not a Number) value as element. It returns a boolean value for all the elements of the vector.

    Syntax: is.nan(x)

    Parameters:
    x: Vector to be checked

    Example:

    # R program to illustrate

    # the use of is.nan() function

    # Creating a vector

    x <- c(1, 2, -Inf, NaN, NaN, NaN)

    # Calling is.nan() function

    is.nan(x)

    Output:

    [1] FALSE FALSE FALSE TRUE TRUE TRUE

    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 : 04 Jun, 2020

    Like Article

    Save Article

    Share your thoughts in the comments

    Please Login to comment...

    Check if the elements of a Vector are Finite, Infinite or NaN values in R Programming - is.finite(), is.infinite() and is.nan() Function - GeeksforGeeks (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Eusebia Nader

    Last Updated:

    Views: 6311

    Rating: 5 / 5 (60 voted)

    Reviews: 91% of readers found this page helpful

    Author information

    Name: Eusebia Nader

    Birthday: 1994-11-11

    Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

    Phone: +2316203969400

    Job: International Farming Consultant

    Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

    Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.