##### Quick Contact

##### R Programming Tutorial

#### R Operators

##### What are Operators in R

The operators are those symbols which tell the compiler for performing precise mathematical or logical manipulations. R programming is loaded with built in operators and supplies below mentioned types of operators.

##### Types of Operators

- The Arithmetic Operators
- The Relational Operators
- The Logical Operators
- The Assignment Operators

The below mentioned table gives the arithmetic operators hold up by R language. The operators act on each element of the vector.

__Arithmetic Operators__

Arithmetic operators are the symbols which are used to represent arithmetic math operations. The operators act on each and every element of the vector. There are various arithmetic operators which are supported by R.

g <- c (4,6.5,6)

s <- c (8,3,5)

print(g + s)

##### Subtract

g <- c (2,5.5,6)

s <- c (8,3,4)

print(g – s)

##### Multiply

g <- c (26.5,8)

s <-c(6,4,3)

print(g * s)

##### Divide

g <-c(2,4.6,8)

s <-c(8,4,3)

print(g / s)

##### Modulus

g <- c (2,5.5,8)

s <- c (8,4,5)

print(g%/%s)

__Relational Operators__

A relational operator is a symbol which defines some kind of relation between two entities. These include numerical equalities and inequalities. A relational operator compares each element of the first vector with the corresponding element of the second vector. The result of the comparison will be a Boolean value. There are the following relational operators which are supported by R:

##### Greater than

g <- c (2,5.5,6,9)

s <- c (8,2.5,14,9)

print(g > s)

##### Less than

g <- c (2,5.6,6,9)

s <-c(8,2.5,14,9)

print(g < s)

##### Equals Operator

g <- c (2,5.5,6,9)

s <- c (8,2.5,14,9)

print(g == s)

##### Less than or equal

g <- c (2,5.5,6,9)

s <- c (8,2.5,14,9)

print(g <= s)

##### Greater than or equal

g <-c(2,5.5,6,9)

s <-c(8,2.5,14,9)

print(g>=s)

##### Not equal

g <-c(2,5.4,8,9)

s <-c(8,2.5,14,8)

print(v!=t)

__Logical Operators__

Here are the set of logical operators that R language allows to use. This operator is valid only to vectors of type logical, number or complex numbers. All figures greater than one is considered to be logical value i.e. TRUE.

##### Element-wise Logical AND Operator

g <-c(3,1, TRUE,2+3i)

s <-c(4,1,FALSE,2+3i)

print(g & s)

It unites each element of the 1st vector with the equivalent element of the 2nd vector and returns TRUE or FALSE.

##### Element-wise Logical OR Operator

g <-c(3,0, TRUE,2+2i)

s <-c(4,0, FALSE,2+3i)

print(g | s)

It unites each element of the 1st vector with the equivalent element of the 2nd vector.

##### Logical NOT Operator

k <- c (3,0, TRUE,2+2i)

print(!k)

##### Logical AND Operator

g <-c(3,0,TRUE,2+2i)

s <-c(1,3,TRUE,2+3i)

print(g && s)

##### Logical OR Operator

g <- c (0,0,TRUE,2+2i)

s <- c (0,3,TRUE,2+3i)

print(g||s)

__Assignment Operator__

An assignment operator is used to assign a new value to a variable. In R, these operators are used to assign values to vectors. There are the following types of assignment.There are three types of operators used for assigning values to vectors.

g1 <- c (2,1,TRUE,2+3i)

g2 <<- c (2,1,TRUE,2+3i)

g3 = c (2,1, TRUE,2+3i)

print(g1)

print(g2)

print(g3)