Search code examples
rdplyr

What do %/% and %% mean?


I've recently seen code like this:

library(dplyr)
mtcars %.% mutate(carb_10 =  carb %/% 10)

And this....

mtcars %.% mutate(carb_10 =  carb %% 10)

Can anyone explain what %/% and %% do in above code?


Solution

  • From the ?"%%" help page

    %% indicates x mod y and %/% indicates integer division. It is guaranteed that x == (x %% y) + y * ( x %/% y ) (up to rounding error) unless y == 0 where the result of %% is NA_integer_ or NaN (depending on the typeof of the arguments).