Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

Comparison Operators in R

by suresh

The Comparison operators in R Programming are mostly used either in If Conditions or Loops. R Relational operators are commonly used to check the relationship between two variables.

  • If the relation is true then it will return Boolean True
  • If the relation is false then it will return Boolean False.

Below table shows all the Relational Operators in R Programming with examples.

Comparison Operators in RUsageDescriptionExample
>i > ji is greater than j25 > 14 returns True
<i < ji is less than j25 < 14 returns False
>=i >= ji is greater than or equal to j25 >= 14 returns True
<=i <= ji is less than or equal to j25 <= 14 return False
==i == ji is equal to j25 == 14 returns False
!=i != ji is not equal to j25 != 14 returns True

Comparison Operators in R Programming Example

This example helps you to understand the Comparison Operators in R Programming language practically. For this example, We are using two variables a and b and their respective values are 15 and 12. We are going to use these two variables to perform various relational operations present in R Programming

# Example for Comparison Operators in R Programming
a <- 15
b <- 12

print(paste("Output of 15 > 12 is : ", a > b))
print(paste("Output of 15 < 12 is : ", a < b))
print(paste("Output of 15 >= 12 is : ", a >= b))
print(paste("Output of 15 <= 12 is : ", a <= b))
print(paste("Output of 15 Equal to 12 is : ", a == b))
print(paste("Output of 15 Not Equal to 12 is : ", a != b))

OUTPUT

Comparison Operators in R Programming 1

ANALYSIS

We assigned two integer values a, b and we assigned the values 15 and 12 using the below statement.

a <- 15
b <- 12

In the next lines, We checked these values against each and every comparison operator (relational operator) present in the R Programming language.

R Comparison Operators in IF Statement

This example helps you to understand, how to use Comparison operators inside the If statements. For this example, We are using two variables x and y and their values are 25 and 25. We are going to use these two variables inside the If condition along with one of the comparison operator present in R programming to check the condition.

# Example for Relational Operators in R Programming
x <- 25
y <- 25
if(x == y) {
  print("x is Equal to y")
} else {
  print("x is NOT Equal to y")
}

OUTPUT

Comparison Operators in R Programming 2

ANALYSIS

We assigned two integer values x, y and assigned the values 25 and 25 using the below statement.

x <- 25
y <- 25

If Condition

If x is equal to y then the first print statement will be executed

print("x is Equal to y")

If the first condition fails then the second print statement will be executed.

print("x is NOT Equal to y")

Here 25 is equal to 25 so, the First print statement is printed

Thank You for Visiting Our Blog.

Placed Under: R Programming

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy