Relational Operators in R Programming Language: Explanation and Usage
☰Fullscreen
Table of Content:
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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a>b) 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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a < b) 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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a == b) 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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a<=b) 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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a>=b) 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 <- c(2,5.5,6,9) b <- c(8,2.5,14,9) print(a!=b) 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