round_preserve_sum: Round preserve sum.

Description Usage Arguments Value Source Examples

Description

Rounds a vector of numbers while preserving the sum of them.

Usage

1
round_preserve_sum(x, digits = 0)

Arguments

x

A numeric vector.

digits

The number of digits to take in account in the rounding process.

Value

round_preserve_sum returns y with round vector.

Source

https://www.r-bloggers.com/round-values-while-preserve-their-rounded-sum-in-r/ and http://stackoverflow.com/questions/32544646/round-vector-of-numerics-to-integer-while-preserving-their-sum

Examples

1
2
3
4
5
sum(c(0.333, 0.333, 0.334))
round(c(0.333, 0.333, 0.334), 2)
sum(round(c(0.333, 0.333, 0.334), 2))
round_preserve_sum(c(0.333, 0.333, 0.334), 2)
sum(round_preserve_sum(c(0.333, 0.333, 0.334), 2))

WaceroRuge/GFE documentation built on May 22, 2019, 2:44 p.m.