R Operators

Last Updated : 20 Feb, 2026

Operators in R are symbols that perform operations on variables and values (operands). They allow you to carry out mathematical calculations, logical comparisons, assignments and other operations efficiently.

operators
Operators in R

Arithmetic Operators

Arithmetic operators perform mathematical operations on numeric values or vectors. In R, these operations are applied element-wise when working with vectors.

1. Addition (+)

The values at the corresponding positions of both operands are added.

R
a <- c (1, 0.1)
b <- c (2.33, 4)
print (a+b)

Output
[1] 3.33 4.10

2. Subtraction (-)

The second operand values are subtracted from the first.

R
 a <- 6
 b <- 8.4
 print (a-b)

Output
[1] -2.4

3. Multiplication (*) 

The multiplication of corresponding elements of vectors and Integers are multiplied with the use of the '*' operator.

R
b= c(4,4) 
c= c(5,5)
print (b*c)

Output
[1] 20 20

4. Division (/) 

The first operand is divided by the second operand with the use of the '/' operator.

R
 a <- 10
 b <- 5
 print (a/b)

Output
[1] 2

5. Power (^)

The first operand is raised to the power of the second operand.

R
 a <- 4
 b <- 5
 print(a^b)

Output
[1] 1024

6. Modulo (%%)

It returns the remainder after dividing the first operand by the second operand.

R
a<- c(2, 22)
b<-c(2,4)
print(a %% b)

Output
[1] 0 2

Logical Operators

Logical Operators in R simulate element-wise decision operations, based on the specified operator between the operands, which are then evaluated to either a True or False boolean value. Any non-zero integer value is considered as a TRUE value, be it a complex or real number. 

1. Element-wise AND (&)

Returns True if both the operands are True.

R
a <- c(TRUE, 0.1)
b <- c(0,4+3i)
print(a & b)

Output
[1] FALSE  TRUE

2. Element-wise OR (|)

Returns True if either of the operands is True.

R
a <- c(TRUE, 0.1)
b <- c(0,4+3i)
print(a|b)

Output
[1] TRUE TRUE

3. NOT (!)

A unary operator that negates the status of the elements of the operand.

R
a <- c(0,FALSE)
print(!a)

Output
[1] TRUE TRUE

4. Short-circuit AND (&&)

Returns True if both the first elements of the operands are True.

R
a <- c(TRUE, 0.1)
b <- c(0,4+3i)
print(a[1] && b[1])

Output
[1] FALSE

5. Short-circuit OR (||)

Returns True if either of the first elements of the operands is True.

R
a <- c(TRUE, 0.1)
b <- c(0,4+3i)
print(a[1]||b[1])

Output
[1] TRUE

Relational Operators

The Relational Operators in R carry out comparison operations between the corresponding elements of the operands. Returns a boolean TRUE value if the first operand satisfies the relation compared to the second. A TRUE value is always considered to be greater than the FALSE. 

1. Less than (<)

Returns TRUE if the corresponding element of the first operand is less than that of the second operand. Else returns FALSE.

R
a <- c(TRUE, 0.1,"apple")
b <- c(0,0.1,"bat")
print(a<b)

Output
[1] FALSE FALSE  TRUE

2. Less than or equal to (<=)

Returns TRUE if the corresponding element of the first operand is less than or equal to that of the second operand. Else returns FALSE.

R
a <- c(TRUE, 0.1, "apple")
b <- c(TRUE, 0.1, "bat")

c <- as.character(a)
d <- as.character(b)

print(c <= d)

Output
[1] TRUE TRUE TRUE

3. Greater than (>)

Returns TRUE if the corresponding element of the first operand is greater than that of the second operand. Else returns FALSE.

R
a <- c(TRUE, 0.1, "apple")
b <- c(TRUE, 0.1, "bat")
print(a > b)

Output
[1] FALSE FALSE FALSE

4. Greater than or equal to (>=)

Returns TRUE if the corresponding element of the first operand is greater or equal to that of the second operand. Else returns FALSE.

R
a <- c(TRUE, 0.1, "apple")
b <- c(TRUE, 0.1, "bat")
print(a >= b)

Output
[1]  TRUE  TRUE FALSE

5. Not equal to (!=) 

Returns TRUE if the corresponding element of the first operand is not equal to the second operand. Else returns FALSE.

R
a <- c(TRUE, 0.1,'apple')
b <- c(0,0.1,"bat")
print(a!=b)

Output
[1]  TRUE FALSE  TRUE

Assignment Operators

Assignment Operators in R are used to assigning values to various data objects in R. The objects may be integers, vectors or functions. These values are then stored by the assigned variable names.

1. Left Assignment (<- , <<- , =)

Assigns a value to a vector.

R
vec1 = c("ab", TRUE) 
print (vec1)

Output
[1] "ab"   "TRUE"

2. Right Assignment (-> , ->>)

Assigns value to a vector.

R
c("ab", TRUE) ->> vec1
print (vec1)

Output
[1] "ab"   "TRUE"

Miscellaneous Operators

Miscellaneous Operator are the mixed operators in R that simulate the printing of sequences and assignment of vectors, either left or right-handed. 

1. %in% Operator 

Checks if an element belongs to a list and returns a boolean value TRUE if the value is present  else FALSE.

R
 val <- 0.1
 a <- c(TRUE, 0.1,"apple")
 print (val %in% a)

Output
[1] TRUE

2. %*% Operator (Matrix Multiplication)

The %*% operator performs matrix multiplication.

  • Columns of the first matrix must equal rows of the second.
  • If A is (r × c) and B is (c × r), the result is (r × r).
R
 mat = matrix(c(1,2,3,4,5,6),nrow=2,ncol=3)
         print (mat)
         print( t(mat))
         pro = mat %*% t(mat)
         print(pro)

Output
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6
     [,1] [,2]
[1,]    1    2
[2,]    3    4
[3,]    5    6
     [,1] [,2]
[1,]   35   44
[2,]   44   56
Comment

Explore