Table of Contents
Arithmetic Operators in R Programming Language: Explanation and Examples
Arithmetic Operators
Following table shows the arithmetic operators supported by R language. The operators act on each element of the vector.
| Operator | Description | Example |
|---|---|---|
| + | Adds two vectors |
it produces the following result −
|
| − | Subtracts second vector from the first |
it produces the following result −
|
| * | Multiplies both vectors |
it produces the following result −
|
| / | Divide the first vector with the second |
When we execute the above code, it produces the following result −
|
| %% | Give the remainder of the first vector with the second |
it produces the following result −
|
| %/% | The result of division of first vector with second (quotient) |
it produces the following result −
|
| ^ | The first vector raised to the exponent of second vector |
it produces the following result −
|
More Examples
> x <- 5
> y <- 16
> x+y
[1] 21
> x-y
[1] -11
> x*y
[1] 80
> y/x
[1] 3.2
> y%/%x
[1] 3
> y%%x
[1] 1
> y^x
[1] 1048576