Table of Contents

    Relational Operators in R Programming Language: Explanation and Usage

    Relational Operators in R Programming Language: Explanation and Usage

    Relational Operators

    Following table shows the relational operators supported by R language. Each element of the first vector is compared with the corresponding element of the second vector. The result of comparison is a Boolean value.

    Operator Description Example
    > Checks if each element of the first vector is greater than the corresponding element of the second vector.
    a

    it produces the following result −

    [1] FALSE  TRUE FALSE FALSE
    < Checks if each element of the first vector is less than the corresponding element of the second vector.
    a

    it produces the following result −

    [1]  TRUE FALSE  TRUE FALSE
    == Checks if each element of the first vector is equal to the corresponding element of the second vector.
    a

    it produces the following result −

    [1] FALSE FALSE FALSE  TRUE
    <= Checks if each element of the first vector is less than or equal to the corresponding element of the second vector.
    a

    it produces the following result −

    [1]  TRUE FALSE  TRUE  TRUE
    >= Checks if each element of the first vector is greater than or equal to the corresponding element of the second vector.
    a

    it produces the following result −

    [1] FALSE  TRUE FALSE  TRUE
    != Checks if each element of the first vector is unequal to the corresponding element of the second vector.
    a

    it produces the following result −

    [1]  TRUE  TRUE  TRUE FALSE

    More Exampels

    > x <- 5
    > y <- 16
    > x<y
    [1] TRUE
    > x>y
    [1] FALSE
    > x<=5
    [1] TRUE
    > y>=20
    [1] FALSE
    > y == 16
    [1] TRUE
    > x != 5
    [1] FALSE