# R Operators

A symbol that tells the compiler to perform specific mathematical or logical operations is called operator.

R language supports mainly 5 different types of operators, which are listed below:

1. Arithmetic operators: These types of operators are used to perform arithmetic operations like addition, subtraction, multiplication, division, etc.
 Operator Description Example + Addition > x =10 > y = 20 > x+y Output:  30 – Subtraction > x =20 > y = 10 > x-y Output:  10 * Multiplication > x = 20 > y = 10 > x*y Output:  200 / Division > x = 20 > y = 10 > y/x Output:  0.5 %% Modulus(Remainder from division) > x = 20 > y = 10 > x%%y Output:  0 %/% Integer Division > x = 20 > y = 10 > y%/%x Output:  0 ^ or ** Exponent > x = 5 > y = 2 > x^y Output:  25
1. Relational Operators: Relational operators define the relation between two entities.
 Operator Description Example > Greater than > x = 10 > y = 20 > x>y Output:  FALSE < Less than > x = 10 > y = 20 > x x = 10 > y = 20 > x<=y Output:  TRUE >= Greater than or equal to > x = 10 > y = 20 > x>=y Output:  FALSE == Equal to > x = 10 > y = 20 > x==y Output:  FALSE != Not equal to > x = 10 > y = 20 > x!=y Output:  TRUE
1. Logical Operators: Logical operators are used to compare the two entities and are typically used with Boolean values.
 Operator Description Example ! Logical NOT > x<- c(TRUE, FALSE, 0, 6) > !x Output:  FALSE TRUE TRUE FALSE & Element wise logical AND (element-wise comparison between vectors and return a logical vector) > x <- c(TRUE, FALSE, 0, 6) > y <- c(FALSE, TRUE, FALSE, TRUE) > x&y Output:  FALSE FALSE FALSE TRUE && Logical AND (compare just the first elements of each vector and return a single logical value) > x <- c(TRUE, FALSE, 0, 6) > y <- c(FALSE, TRUE, FALSE, TRUE) > x&&y Output:  FALSE | Element-wise logical OR (element-wise comparison between vectors and return a logical vector) > x <- c(TRUE, FALSE, 0, 6) > y <- c(FALSE, TRUE, FALSE, TRUE) > x|y Output:  TRUE TRUE FALSE TRUE || Logical OR (compare just the first elements of each vector and return a single logical value) > x <- c(TRUE, FALSE, 0, 6) > y <- c(FALSE, TRUE, FALSE, TRUE) > x||y Output:  TRUE
1. Assignment operators: It is used to assign values.
 Operator Description Example <- or <<- or = Left assignment > x <- 10 > y = 20 > z <<- 30 > x > y > z Output:  10  20  30 -> Or ->> Right assignment > 10 -> x > 20 ->> y > x > y Output:  10  20
1. Miscellaneous operators:
 Operator Description Example : Colon used to create a series of numbers in sequence > v <- 10:15 > v Output: 10 11 12 13 14 15 %in% Used to check if an element belongs to a vector > a = 10 > b = 100 > c = 10:15 > a %in% c > b %in% c Output: TRUE FALSE