R Equal-To Operator

R – Equal-To Operator == is used to check if its two operands are exactly equal to each other.

== symbol is used for Equal-To Operator in R Language.

The syntax of Equal-To Operator with the two operands is

</>
Copy
operand1 == operand2

Equal-To Operator takes two operands and returns a boolean value of TRUE if the two operands are exactly equal to each other, or FALSE otherwise.

Examples

Check If Two Boolean Values are Equal

In the following R program, we will take two boolean values and check if they are equal using Equal-To Operator.

example.r

</>
Copy
x <- TRUE
y <- TRUE
result <- x == y
cat(x, "==", y, " is ", result, "\n")

x <- TRUE
y <- FALSE
result <- x == y
cat(x, "==", y, " is ", result, "\n")

Output

tutorialkart$ Rscript example.r
TRUE == TRUE  is  TRUE 
TRUE == FALSE  is  FALSE

Check If Two String Values are Equal

In the following R program, we will take two string values and check if they are equal using Equal-To Operator.

example.r

</>
Copy
x <- "apple"
y <- "banana"
result <- x == y
cat(x, "==", y, " is ", result, "\n")

x <- "apple"
y <- "apple"
result <- x == y
cat(x, "==", y, " is ", result, "\n")

Output

apple == banana  is  FALSE 
apple == apple  is  TRUE 

Check If Two Numbers are Equal

In the following R program, we will take two numbers in x and y, and check if they are equal using Equal-To Operator.

example.r

</>
Copy
x <- 3
y <- 4
result <- x == y
cat(x, "==", y, " is ", result, "\n")

x <- 2
y <- 2
result <- x == y
cat(x, "==", y, " is ", result, "\n")

Output

3 == 4  is  FALSE 
2 == 2  is  TRUE

Conclusion

Concluding this R Tutorial, we learned what R Equal-To Operator is, and how to use it to check if two objects or values are exactly equal.