Skip to content
Share
Explore

R Operators

Operators are used to perform operations on variables and values.
1) Arithmetic operators are used with numeric values to perform common mathematical operations.
Arithmetic Operators
Operator
Name
Example
Result
+
Addition
20+3
23
-
Subtraction
20-3
17
*
Multiplication
20*3
60
/
Division
20/3
6.666667
^
Exponent
20^3
8000
%%
Modulus
20%%3
2
%/%
Integer Division (round down)
20%/%3
6
There are no rows in this table
2) Assignment operators are used to assign values to variables.
my_var <- 3
my_var <<- 3
3 -> my_var
3 ->> my_var

## x <- 3 is equal to 3 -> x
## Note: <<- is a global assigner.

3) Comparison operators are used to compare two values.
Comparison Operators
==
Equal
x == y
!=
Not equal
x != y
>
Greater than
x > y
<
Less than
x < y
>=
Greater than or equal to
x >= y
<=
Less than or equal to
x <= y
There are no rows in this table
4) Logical operators are used to combine conditional statements.
Logical Operators
There are no rows in this table
x <- c(TRUE, FALSE, TRUE)
y <- c(FALSE, TRUE, TRUE)
x & y

## Output:
[1] FALSE FALSE TRUE
x <- 5
if (x > 0 && x < 10)
{
print("x is positive and less than 10")
}
else
{
print("x is either negative or greater than 10")
}

## Output:
[1] "x is positive and less than 10"

5) Miscellaneous operators are used to manipulate data
Miscellaneous Operators
There are no rows in this table

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.