Nothing wrong:
10 = 1 * 10 + 0 20 = 2 * 10 + 0 10 = 0 * 20 + 10 2 = 0 * 8 + 2
The modulo is the number after +
.
In general, for two numbers a
and b
, there is
a = floor(a / b) * b + (a %% b)
Let’s write a toy function:
foo <- function(a,b) c(quotient = floor(a / b), modulo = a %% b) foo(10, 10) #quotient modulo # 1 0 foo(20, 10) #quotient modulo # 2 0 foo(10, 20) #quotient modulo # 0 10 foo(2, 8) #quotient modulo # 0 2
Update: Instead of using floor(a / b)
to get quotient, we can also use a %/% b
.
Related Posts:
- Does Python have a ternary conditional operator?
- Which equals operator (== vs ===) should be used in JavaScript comparisons?
- How is the AND/OR operator represented as in Regular Expressions?
- Behaviour of increment and decrement operators in Python
- Is there a “not equal” operator in Python?
- What exactly does += do in python?
- Use of “instanceof” in Java [duplicate]
- What is the result of % in Python?
- Does Python have a ternary conditional operator?
- Is there a “not equal” operator in Python?
- What are XAND and XOR
- What does the ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- What does operator “dot” (.) mean?
- ^=, -= and += symbols in Python
- What does ‘&’ do in a C++ declaration?
- Creating a “logical exclusive or” operator in Java
- What does “|=” mean? (pipe equal operator)
- What are bitwise shift (bit-shift) operators and how do they work?
- Error: “expression must have integral or unscoped enum type” [duplicate]
- PowerShell and the -contains operator
- Logical XOR operator in C++?
- Regex how to match an optional character
- What does the question mark character (‘?’) mean in C++?
- proper name for python * operator?
- proper name for python * operator?
- What does the power operator (**) in python translate into?
- what is the meaning of == sign?
- What does the question mark character (‘?’) mean in C++?
- The difference between += and =+
- PowerShell and the -contains operator
- What does the percentage sign mean in Python
- Regex how to match an optional character
- Reference — What does this symbol mean in PHP?
- Plot multiple lines in one graph
- Replace a value in a data frame based on a conditional (`if`) statement
- How to read in .HTM into R as a data frame?
- Create empty data frame with column names by assigning a string vector?
- Changing font size and direction of axes text in ggplot2
- What does question mark and dot operator ?. mean in C# 6.0?
- How to randomize ggplot factor color scheme, keeping same default distances on color wheel?
- Count number of occurences for each unique value
- Warning message: line appears to contain embedded nulls [duplicate]
- Find duplicate values in R
- How to change line width in ggplot?
- Error in library(ggplot2) : There is no package called ‘ggplot2’
- Transpose a data frame
- How to drop columns by name in a data frame
- How to reshape data from long to wide format
- Change size of axes title and labels in ggplot2
- Multiple If Statements in R
- ggplot geom_text font size control
- The tilde operator in Python
- What’s the difference between lapply and do.call?
- ggplot2, change title size
- Combine two or more columns in a dataframe into a new column with a new name
- Not equal to != and !== in PHP
- Initial value in ‘vmmin’ is not finite even when changing the starting value
- Insert picture/table in R Markdown
- Test if a vector contains a given element
- R “Error: unexpected ‘}’ in “}”
- What does `<>` mean in Python?
- How to remove outliers from a dataset
- Insert a blank column in dataframe
- “length of ‘dimnames’ [2] not equal to array extent” on one of two very similar sets
- What is ‘\0’ in C++?
- Mean per group in a data.frame
- How to install RHadoop packages (Rmr, Rhdfs, Rhbase)?
- What is a Question Mark “?” and Colon “:” Operator Used for?
- What does the percentage sign mean in Python
- Error in dev.off() : cannot shut down device 1 (the null device)
- How to create an empty matrix in R?
- standard deviation on dataframe does not work
- Warning message: In `…` : invalid factor level, NA generated
- How to increase font size in a plot in R?
- What is the difference between ‘/’ and ‘//’ when used for division?
- ruby operator “=~” [duplicate]
- What is the difference between = and ==?
- What does << mean in Ruby?
- What does =~ do in Perl?
- Merge r brings error “‘by’ must specify uniquely valid columns”
- Subscripts in plots in R
- promise already under evaluation: recursive default argument reference or earlier problems?
- What does the error “arguments imply differing number of rows: x, y” mean?
- Aggregate multiple columns at once
- error: ‘ostream’ does not name a type
- What does the colon (:) operator do?
- Error in model.frame.default: variable lengths differ
- Non-numeric argument to mathematical function
- Is there an exponent operator in C#?
- Position-dodge warning with ggplot boxplot?
- Plot two graphs in same plot in R
- What does ||= (or-equals) mean in Ruby?
- data.table vs dplyr: can one do something well the other can’t or does poorly?
- R – Concatenate two dataframes?
- KNN in R: ‘train and class have different lengths’?
- Error in rep(1, n.ahead) : invalid ‘times’ argument in R
- Producing subscripts in R markdown
- ggplot geom_text font size control