internalRoundFixedSum | R Documentation |
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).
internalRoundFixedSum(v, roundSum = round)
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. |
out A vector of v with the values rounded to whole numbers but with the whole number sum preserved.
Gallagher M. Proportionality, disproportionality and electoral systems. Electoral Studies. 1991;10(1)33-51. doi:10.1016/0261-3794(91)90004-C.
Other data functions:
internalSubAsRest()
library(nbc4va) dec <- c(rep(50/2, 2), rep(50/3, 3)) whole <- nbc4va::internalRoundFixedSum(dec)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.