Round values preserving their sum. Often used to round percentages such that their totals still add to 100
round_preserve_sum(x, digits = 0)
x | numeric vector to round |
---|---|
digits | integer indicating the number of decimal places to be used |
a numeric value
#> [1] 100#> [1] 99# Using round_preserve_sum ensures the rounded values add to 100 round_preserve_sum(x)#> [1] 10 20 70#> [1] 100