%% in r language gives the modulus of two numbers. It is basically the remainder of division of first number by second number.

Consider this code –

a = 5
b = 2
a %% b
[1] 1

Here we are doing 5 %% 2 which says that we want the remainder of 5 / 2. So,

  • 5 = Dividend
  • 2 = Divisor
  • 5 / 2 = Quotient
  • 5 %% 2 = Remainder

And according to mathematics –

Dividend = ( Divisor x Quotient ) + Remainder

So, a = (b x int(a / b)) + (a %% b)

Β Β Β Β Tweet this to help others

Live Demo

Demo might not work in private window (incognito)

R

Tagged in:

Comments

About the Author

akamit

I am Akash Mittal, an overall computer scientist. If you want to guest post, need help in your projects, want to advertise, Feel free to contact me at [email protected]

View All Articles