Round values while preserve their rounded sum in R
Source:R/round_preserve_sum.R
round_preserve_sum.Rd
Sometimes, the sum of rounded numbers (e.g., using base::round()
) is not
the same as their rounded sum.
Details
This solution applies 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