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?
- How is the AND/OR operator represented as in Regular Expressions?
- What is the result of % in Python?
- Does Python have a ternary conditional operator?
- What does the ^ (XOR) operator do? [duplicate]
- What do these operators mean (** , ^ , %, //)? [closed]
- 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]
- Logical XOR operator in C++?
- Regex how to match an optional character
- proper name for python * operator?
- The difference between += and =+
- What does the percentage sign mean in Python
- Plot multiple lines in one graph
- Create empty data frame with column names by assigning a string vector?
- Changing font size and direction of axes text in ggplot2
- Warning message: line appears to contain embedded nulls [duplicate]
- How to change line width in ggplot?
- Error in library(ggplot2) : There is no package called ‘ggplot2’
- 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
- The tilde operator in Python
- ggplot2, change title size
- Combine two or more columns in a dataframe into a new column with a new name
- R “Error: unexpected ‘}’ in “}”
- What does `<>` mean in Python?
- What is ‘\0’ in C++?
- What is a Question Mark “?” and Colon “:” Operator Used for?
- What does the percentage sign mean in Python
- How to create an empty matrix in R?
- How to increase font size in a plot in R?
- Subscripts in plots in R
- error: ‘ostream’ does not name a type
- What does the colon (:) operator do?
- Is there an exponent operator in C#?
- Position-dodge warning with ggplot boxplot?
- data.table vs dplyr: can one do something well the other can’t or does poorly?
- Error in rep(1, n.ahead) : invalid ‘times’ argument in R
- Producing subscripts in R markdown
- ggplot geom_text font size control
- Multiple OR or AND conditions in IF statement
- lme4::lmer reports “fixed-effect model matrix is rank deficient”, do I need a fix and how to?
- How do you use “<<-" (scoping assignment) in R?
- Convert data.frame columns from factors to characters
- Re-ordering factor levels in data frame
- Is it possible to have a multi-line comments in R?
- Simple manual RMarkdown tables that look good in HTML, PDF and DOCX
- Select rows from a data frame based on values in a vector
- Reference — What does this symbol mean in PHP?
- how to increase the limit for max.print in R
- backward elimination in R
- How to compute summation in r
- Plot multiple boxplot in one graph
- R will plot but won’t draw abline
- scale_fill_discrete and scale_fill_manual – legend options confusion
- R – argument is of length zero in if statement
- ‘Incomplete final line’ warning when trying to read a .csv file into R
- Merging data – Error in fix.by(by.x, x)
- Error in 2:n : NA/NaN argument
- Error in generating boxplot two variable data frame: adding class “factor” to an invalid object
- Error : Unable to start png() device
- Remove NA values from a vector
- How to catch integer(0)?
- “no function to return from, jumping to top level”
- r random forest error – type of predictors in new data do not match
- env=baseenv() in R
- How to set axis range R
- Is there a “not in” operator in JavaScript for checking object properties?
- What does the error “object not interpretable as a factor” mean?
- use first row data as column names in r
- Gradient of n colors ranging from color 1 and color 2
- What is the difference between require() and library()?
- R Sweave: NO TeX installation detected
- Plotting legend outside plot in R
- Boolean operators && and ||
- R avoiding “restarting interrupted promise evaluation” warning
- do-while loop in R
- ERROR: [on_request_read] connection reset by peer in R shiny
- Error in as.vector(x, mode) : cannot coerce type ‘closure’ to vector of type ‘any’
- Suppress output of a function
- Get dplyr count of distinct in a readable way
- r function unzip error 1 in extracting from zip file
- Colour points in a plot differently depending on a vector of values
- increase legend font size ggplot2
- How To Create Vector of Vector In R
- Round down a numeric
- Use of ~ (tilde) in R programming Language
- What are the double colons (::) in R?
- Using OR operator in a jQuery if statement
- OCaml mod function returns different result compared with %
- Does the c command create a row vector or a column vector by default in R
- Can dplyr join on multiple columns or composite key?
- Convert data.frame column to a vector?
- The tilde operator in C
- Prolog “or” operator, query