# %% in r language

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

## Live Demo

Demo might not work in private window (incognito)

Get only the best articles delivered to your mail

## R lang – Remove rows in dataframe

R lang provides the – operator to remove rows from dataframe. Simply provide the indexes of rows to remove with – sign. Consider this example – Here we have created…

## \$ operator is invalid for atomic vectors – R Error

Table of Contents Hide Check if vector is atomic or recursiveConvert vector to listLive DemoRelated Posts: In R language, you get the error, “\$ operator is invalid for atomic vectors”…

## (list) object cannot be coerced to type ‘double’ – R Error

R-language throws error (list) object cannot be coerced to type ‘double‘ when we try to convert a list of string or other type values to a numeric vector. To correctly…

## Warning: the condition has length > 1 and only the first element will be used

R-lang throws the warning, the condition has length > 1 and only the first element will be used because if statement is not vectorized. In it’s place you need to…

## error in file(file, “rt”) : cannot open the connection

R throws error in file(file, “rt”) : cannot open the connection, when it’s not able to find the file in the provided path. This could happen either due to wrong…