Not equal to in R

Not equal to (!=) is one of the relational operators used for making comparisons. It returns TRUE if the first operand is not equal to the second; else returns FALSE.

Syntax

!=

Example 1: Comparing two objects

78 != 35
TRUE != FALSE
TRUE != TRUE

Output

[1] TRUE
[1] TRUE
[1] FALSE

Example 2: Comparing two variables

Suppose you have two variables, x and y.

#creating variables
x<-30
y<-6
#not equal to
x!=y

Output

[1] TRUE

Example 3: Comparing two vectors

Suppose you have two vectors, v1 and v2.

#creating vectors
v1<-c(171, 152)
v2<-c(182, 165)
#not equal to
v1!=v2

Output

[1] TRUE TRUE

In this example, the Not equal to the operator will compare each element of two vectors. It will return a logical value for each of the elements.

Leave a Comment