What is the purpose of the double percent (percent percent) in R?

It appears that when you use it, it divides the number in front by the number in back as many times as it can and returns the remainder. Is that accurate?

When would this be useful, just out of curiosity?
Jun 14, 2022 328 views

## 1 answer to this question.

According to the "Arithmetic operators" help page (accessible via?" percent percent "),

'x mod y' is indicated by 'percent percent'.

which is only helpful if you've done enough programming to know that this is referring to modular division, i.e. integer-divide x by y and return the remainder. This is applicable in a wide range of situations. For example (from @GavinSimpson in comments), %% is useful if you are running a loop and want to print some kind of progress indicator to the screen every nth iteration (e.g. use if (i %% 10 == 0) { #do something} to do something every 10th iteration).

Since %% also works for floating-point numbers in R, I've just dug up an example where if (any(wts %% 1 != 0)) is used to test where any of the wts values are non-integer.
• 2,960 points

## What does the inf special character mean in R?

inf stands for infinity and only applies ...READ MORE

+1 vote

The error means that R could not ...READ MORE

+1 vote

## R has something called lazy evaluation, what does that mean?

Let me explain this with an example. ...READ MORE

+1 vote

## What does “replacement has” Error mean?

This error occurs when one tries to ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

## Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

The below is the code to perform ...READ MORE