smartround: Round a vector of floating-point values while preserving their sum
Description
Rounds the values in a vector up and down, preserving the sum of the vector and minimizing the total rounding error under this condition. An example where this is useful is when rounding a vector of percentages, where the total should add up to 100 percent.
Usage
smartround(x, digits = 0)
Value
Returns a vector of rounded values of the same length as x.
Arguments
x
vector of values
digits
optional non-negative integer specifying the number of digits of the rounded numbers