Condition operators · #24

This snippet needs the following libraries: base · How to load the right library →

To check for a condition, use one of the following condition operators:

  • >: strictly bigger
  • <: strictly lower
  • ==: equal to. Please note that you need to use two equal signs.
  • >=: bigger or equal
  • <=: lower or equal
  • !=: not equal/different to
x > y
x < y
x == y
x >= y
x <= y
x != y

Any condition check gives TRUE if the condition is met or FALSE if the condition is not met.

Dive deeper

To check for multiple conditions at the same time, use:

  • & (&&), "AND": check if the two conditions are met at the same time
  • | (||), "OR": check if at least one of the two conditions is met
x < y & is.numeric(x) == TRUE
x == "Nancy" | x == "Metz"

The first line is TRUE if x is lower than y and is of type numeric. The second line is TRUE is x is either "Nancy" or "Metz".

To check if an object is or is not in a predefined list, see:

Documentation

R: Relational Operators
R: Logical Operators

Access ready-to-use R code snippets

Unlock now