Round a numeric vector so it sums exactly to 100
round_preserve_100.Rd
Floors values and then distributes the remaining units to the entries with the largest fractional parts (the “largest remainders” method) so that the final vector sums to exactly 100.
Examples
round_preserve_100(c(33.4, 33.3, 33.3))
#> [1] 34 33 33
round_preserve_100(c(12.9, 12.1, 25.5, 49.5))
#> [1] 13 12 26 49
# Edge case: already sums to 100
round_preserve_100(c(10, 20, 30, 40))
#> [1] 10 20 30 40
# Will error if far from 100:
if (FALSE) { # \dontrun{
round_preserve_100(c(10, 10, 10)) # sum = 30
} # }