R: Arithmetic Operators

Arithmetic Operators are used for performing arithmetic operations, like addition, subtraction, multiplication, division and modulo using the specified operator between operands, which can be Numerical, Integers, Complex Numbers or Vectors. Here the operation on vectors is performed on one to one element basis.  

1. Addition Operators (+)

The addition of two operands is performed.

Usage: a+b

2. Subtraction Operator (-)

The subtraction of the second operand is done from the first.

Usage: a-b

3. Multiplication Operator (*)

The multiplication of two operands is performed. The elements at corresponding positions of matrices are multiplied.

Usage: a*b

4. Division Operator (/)

The first operand is divided by the second operand.

Usage: a/b

5. Power Operator (^)

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

Usage: a^b

6. Modulo Operator (%%)

It gives the remainder when the first operand is divided by the second operand.

Usage: a%%b

7. Integer Division (%/%) 

It gives a quotient when the first operand is divided by the second one.

Usage: a%/%b

Examples:

> a<-4
> b<-2
> c<-a+b
> d<-a-b
> e<-a*b
> f<-a/b
> g<-a^b
> h<-a%%b
> i<-a%/%b
>print(c)
>print(d)
>print(e)
>print(f)
>print(g)
>print(h)
>print(i)

Output:

[1] 6 

[1] 2 

[1] 8 

[1] 2 

[1] 16 

[1] 0 

[1] 2