Description Usage Arguments Details Value
Applying the rounding function independently to a vector of numbers does not, in general, preserve their sum. This function ensures that the sum is preserved after rounding.
1 | rounded_sum(x, digits)
|
x |
A numeric vector where it is desired that each number be rounded to 'digits' digits. |
digits |
The number of digits where rounding is applied. |
It achieves this using the following algorithm:
Round down to the specified number of decimal places.
Order numbers by their remainder values.
Increment the specified decimal place of values with k largest remainders, where k is the number of values that must be incremented to preserve their rounded sum.
Returns a vector similar to x, except that the numbers have been rounded and their sum is preserved.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.