View source: R/round_preserve_sum.R
round_preserve_sum | R Documentation |
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
x <- c(10.3, 20.3, 69.4)
# These three values add to 100
sum(x)
# But when rounded they do not add to 100
sum(round(x))
# Using round_preserve_sum ensures the rounded values add to 100
round_preserve_sum(x)
sum(round_preserve_sum(x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.