**Operators**

R has the following data operators:

- Arithmetic Operators
- Assignment Operators
- Logical Operators
- Relational Operators
- Miscellaneous Operators

**Arithmetic Operators**

These operators perform basic arithmetic operations like addition, subtraction, multiplication, division, exponent, modulus, etc.

For example:-

x <- 10 y <- 5

Addition | x+y | Output:15 |

Subtraction | x-y | Output:5 |

Multiplication | x*y | Output:50 |

Division | x/y | Output:2 |

Exponent | x^y | Output:10^5 |

Modulus | x%%y | Output:0 |

**Want to get certified in R! Learn R from top R experts and excel in your career with Intellipaat’s R Programming certification!**

These operators can also be used to carry out mathematical operations on vectors.

For creating vectors, we use the c() function.

In the case of vectors, all these operations are done in an element-by-element fashion.

For example:

xÂ <-Â c(9,9,9) yÂ <-Â c(1,1,1) print(x+y) Output: [1]Â 10 10 10

**Assignment Operators**

The use of these operators is to assign values to the variables. There are two kinds of assignments, leftwards assignment, and rightwards assignment.

Operators â€˜<-â€˜ andÂ â€˜=â€™ are used to assign values to any variable.

x<- 3 or x = 3 (Leftwards Assignment)

3 -> x or x = 3 (Rightwards Assignment)

**Looking for R Course?Â Enroll now!**

**Logical Operators**

These operators are used to perform Boolean operations like AND, OR, NOT, etc. on variables.

Different logical operators are as follows:

! |
– |
NOT |

& |
– |
AND (Element wise) |

&& |
– |
AND |

| |
– |
OR (Element wise) |

|| |
– |
OR |

! |
– |
NOT |

ZEROS are taken as FALSE and NON-ZERO numbers are taken as TRUE.

For example:

x <- c (FALSE, TRUE,3,0) y <- c (FALSE, TRUE, FALSE, TRUE) !xÂ Â Â Â Â Â Â Â (NOT operation) x&yÂ Â Â (AND operation) Output: [1] TRUE FALSE FALSE TRUE [1] FALSE TRUE FALSE FALSE and,x&&y x||y Output: [1] FALSE [1] FALSE

**Get familiar with the top R Programming Interview Questions to get a head start in your career!**

**Relational Operators**

These operators are used to compare two values or variables. To find if one is smaller, greater, equal, not equal, and other similar operations these operators are used. The output of a

A relational operator is always a Logical value, that is either TRUE or FALSE.

For example:-

x <- 10

y <- 5

Greater than | x>y | Output: TRUE |

Less than | x<y | Output: FALSE |

Greater than and equal to | x>=y | Output: TRUE |

Less than and equal to | x<=y | Output: FALSE |

Equal to | x==y | Output: FALSE |

Not equal to | x!=y | Output: TRUE |

**Have you got more queries? Come to our R Programming Community and get them clarified today!**

**Miscellaneous Operators**

These R programming operators are used for special cases and are not for general mathematical or logical computation.

colon operator – It is used to generate a series of numbers in sequence for a vector.

For example:

x <- 0:9 print(x) Output:[1] 0 1 2 3 4 5 6 7 8 9 %in% :-Â This operator is used to check if an element belongs to a vector or not.

For example:

v1 <- 5 t <- 0:9 print(v1 %in% t) Output:[1] TRUE

%* %: This operator multiplies a matrix with its transpose.

For example:

M = matrix( c(1,2,3,4), nrow = 2,ncol = 2,byrow = TRUE) T= M %*% t(M) print(T) Output: [,1] [,2] [1,]Â Â Â 5Â Â 11 [2,]Â Â 11Â Â 25

In this tutorial, we learned about the different R programming operators, and how to use these operators to perform different arithmetic and logical manipulations in R.

**Interested in learning R programming? Click here to learn more in this R programming training in New York!**