Description Usage Arguments Value Examples
View source: R/roundPreserveSum.R
Takes a vector of fractions or integers and rounds them so they are all integers, but the sum of the vector remains the same. There are many names for the method implemented here: see http://www.ams.org/publicoutreach/feature-column/fcarc-apportionii1. This code was adapted from https://biostatmatt.com/archives/2902.
1 | roundPreserveSum(vectorOfNumbersRoundPreserveSum, numDecimals = 0)
|
vectorOfNumbersRoundPreserveSum |
The vector of numbers to round to integers while keep ing the sum the same. |
outVectorOfRoundedNumbers
1 2 3 4 5 | roundPreserveSum(c(0.333, 0.333, 0.334), 2)
sum( roundPreserveSum(c(0.333, 0.333, 0.334), 2) )
roundPreserveSum(c(0.333, 0.333, 0.334), 0)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.