internalRoundFixedSum: Round values to whole numbers while preserving the sum

internalRoundFixedSumR Documentation

Round values to whole numbers while preserving the sum

Description

Rounds a vector of values to whole numbers while preserving the sum (rounded if it is not a whole number) using the largest remainder method (Gallagher, 1991).

Usage

internalRoundFixedSum(v, roundSum = round)

Arguments

v

A vector of values with decimal values and a whole number sum to round.

roundSum

If the sum of the values in v is not a whole number, choose a rounding method to ensure it is a whole number.

Value

out A vector of v with the values rounded to whole numbers but with the whole number sum preserved.

References

  • Gallagher M. Proportionality, disproportionality and electoral systems. Electoral Studies. 1991;10(1)33-51. doi:10.1016/0261-3794(91)90004-C.

See Also

Other data functions: internalSubAsRest()

Examples

library(nbc4va)
dec <- c(rep(50/2, 2), rep(50/3, 3))
whole <- nbc4va::internalRoundFixedSum(dec)


nbc4va documentation built on May 10, 2022, 5:07 p.m.