Arithmetic operation in R

R Programming Language / Operators in R Language

401

Program:

# An addition
5 + 5 

# A subtraction
5 - 5 

# A multiplication
3 * 5

 # A division
(5 + 5) / 2 

# A Exponentiation
2^5

# a Modulo
5 %% 3

# Exponentiation


# Modulo

Output:

> # An addition
> 5 + 5
[1] 10
> 
> # A subtraction
> 5 - 5
[1] 0
> 
> # A multiplication
> 3 * 5
[1] 15
> 
>  # A division
> (5 + 5) / 2
[1] 5
> 
> # A Exponentiation
> 2^5
[1] 32
> 
> # a Modulo
> 5 %% 3
[1] 2
> 
> # Exponentiation
> 
> 
> # Modulo
> # An addition
> 5 + 5
[1] 10
> 
> # A subtraction
> 5 - 5
[1] 0
> 
> # A multiplication
> 3 * 5
[1] 15
> 
>  # A division
> (5 + 5) / 2
[1] 5
> 
> # A Exponentiation
> 2^5
[1] 32
> 
> # a Modulo
> 5 %% 3
[1] 2

Explanation:

Arithmetic with R

In its most basic form, R can be used as a simple calculator. Consider the following arithmetic operators:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Exponentiation: ^
  • Modulo: %%

The last two might need some explaining:

  • The ^ operator raises the number to its left to the power of the number to its right: for example 3^2 is 9.
  • The modulo returns the remainder of the division of the number to the left by the number on its right, for example 5 modulo 3 or 5 %% 3 is 2.

With this knowledge, follow the instructions below to complete the exercise.


This Particular section is dedicated to Programs only. If you want learn more about R Programming Language. Then you can visit below links to get more depth on this subject.