🤡Operators

Operators are the constructs that can manipulate the value of operands. Operators are used to performing operations on variables and values.

R divides the operators into the following groups:

  • Arithmetic operators

  • Assignment operators

  • Comparison operators

  • Logical operators

  • Miscellaneous operators

Arithmetic Operators

Assignment Operators

Assignment operators are used to assigning values to variables:

# Assign a variable
var1 <- 5

# Global variable
var2 <<- 8

# also same
5 -> var1

8 ->> var2

# Print the variables
var1
var2

Note: <<- is a global assigner. You will learn more about this in the Global Variable chapter from W3 Schools.

It is also possible to turn the direction of the assignment operator.

x <- 3 is equal to 3 -> x

Comparison Operators

Comparison operators are used to comparing two values:

Logical Operators

Logical operators are used to combine conditional statements:

NOTE: To understand the difference between & vs && and | vs ||click on the following link: R Basics 9 - Difference between single and double AND OR statements - & vs && and | vs ||

Miscellaneous Operators

Miscellaneous operators are used to manipulating data:

Sources of the contents on this page:

Last updated