Learn

Introduction to R Syntax

Comparison Operators

When writing conditional statements, sometimes we need to use different types of operators to compare values. These operators are called comparison operators.

Here is a list of some handy comparison operators and their syntax:

- Less than:
`<`

- Greater than:
`>`

- Less than or equal to:
`<=`

- Greater than or equal to:
`>=`

- Is equal to:
`==`

- Is NOT equal to:
`!=`

Comparison operators compare the value on the left with the value on the right. For instance:

`10 < 12 # Evaluates to TRUE`

It can be helpful to think of comparison statements as questions. When the answer is “yes”, the statement evaluates to true, and when the answer is “no”, the statement evaluates to false. The code above would be asking: is 10 less than 12? Yes! So 10 < 12 evaluates to true.

Use a comparison operator to check if 56 is greater than or equal to 129. What should this expression evaluate to? Check by running your code!

In a new line, use the right comparison operator to check if 56 is NOT equal to 129. What should this expression evaluate to? Check by running your code!