Relational operators, or comparators, are operators which help us see how one R object relates to another.
For example, you can check whether two objects are equal (equality) by using a double equals sign ==
.
We can see if the logical value of TRUE
equals the logical value of TRUE
by using this query TRUE == TRUE
. The result of the equality query is a logical value ( TRUE or FALSE
). In this case, it is TRUE
because TRUE
equals TRUE
.
On the contrary, TRUE == FALSE
will give us FALSE
.
Apart from logical variables, we can also check the equality of other types, such as strings and numbers.
# Comparing the equality of two strings
"hello" == "goodbye"
# Comparing the equality of two numbers
3 == 2
Both of these output FALSE
.
The most basic form of comparison is equality. Recall that it is represented by the double equations syntax, ==
. Here is an example of some equality statements:
3 == (2 + 1)
"ultimate guide" == "r"
TRUE == FALSE
"Rchitect" == "rchitect"
Notice from the last expression that R is case sensitive: “R” is not equal to “r”.
Try out the following comparisons:
TRUE
equals FALSE
.-6 * 14
is equal to 17 — 101
."useR"
and "user"
are equal in R.TRUE
to the numeric 1.Make sure not to mix up ==
(comparison) and =
(assignment), ==
is what is used to check equality of R objects.
#r #data-analytics #data-analysis #data-science #r-programming