roundPreserveSum: roundPreserveSum Rounds a set of fractions and decimals to...

Description Usage Arguments Value Examples

View source: R/roundPreserveSum.R

Description

Takes a vector of fractions or integers and rounds them so they are all integers, but the sum of the vector remains the same. There are many names for the method implemented here: see http://www.ams.org/publicoutreach/feature-column/fcarc-apportionii1. This code was adapted from https://biostatmatt.com/archives/2902.

Usage

1
roundPreserveSum(vectorOfNumbersRoundPreserveSum, numDecimals = 0)

Arguments

vectorOfNumbersRoundPreserveSum

The vector of numbers to round to integers while keep ing the sum the same.

Value

outVectorOfRoundedNumbers

Examples

1
2
3
4
5
roundPreserveSum(c(0.333, 0.333, 0.334), 2)

sum( roundPreserveSum(c(0.333, 0.333, 0.334), 2) )

roundPreserveSum(c(0.333, 0.333, 0.334), 0)

robiRagan/voteR documentation built on Feb. 27, 2020, 6:48 p.m.