What does the double percentage sign mean

0 votes
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 in Data Analytics by Avinash
• 1,260 points
2,042 views

1 answer to this question.

0 votes

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.

Enhance your data skills with our comprehensive Data Analyst Certification – Enroll now!

answered Jun 14, 2022 by Sohail
• 3,040 points

Related Questions In Data Analytics

0 votes
1 answer

What does the inf special character mean in R?

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

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,840 points
2,453 views
+1 vote
1 answer

What does “Error: object '<myvariable>' not found” mean?

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

answered Oct 29, 2018 in Data Analytics by Ali
• 11,360 points
1,802 views
+1 vote
1 answer

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

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

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
1,002 views
+1 vote
1 answer

What does “replacement has” Error mean?

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

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
488 views
0 votes
1 answer

Big Data transformations with R

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

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
761 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
833 views
0 votes
1 answer

Finding frequency of observations in R

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

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,542 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

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

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
854 views
0 votes
1 answer

What does 'r' mean before a Regex pattern?

Since the string is to be treated ...READ MORE

answered Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
1,045 views
0 votes
1 answer

What does "pch" stand for?

Plot character or pch is the standard ...READ MORE

answered Jun 23, 2022 in Data Analytics by Sohail
• 3,040 points
982 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP