%% in r language

Total
0
Shares

%% 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

Open Live Demo