R Not-Equal-To Operator

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

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

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

operand1 != operand2

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

Examples

Check If Two Boolean Values are Not Equal

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

example.r

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

TRUE != TRUE  is  FALSE 
TRUE != FALSE  is  TRUE

Check If Two String Values are Not Equal

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

example.r

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  TRUE 
apple != apple  is  FALSE

Check If Two Numbers are Not Equal

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

example.r

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  TRUE 
2 != 2  is  FALSE
ADVERTISEMENT

Conclusion

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