What is the double percent (
%%) used for in R?
From using it, it looks as if it divides the number in front by the number in back of it as many times as it can and returns the left over value. Is that correct?
Out of curiosity, when would this be useful?
Best How To :
The "Arithmetic operators" help page (which you can get to via
‘%%’ indicates ‘x mod y’
which is only helpful if you've done enough programming to know that this is referring to modular division, i.e. integer-divide
y and return the remainder. This is useful in many, many, many applications. 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.