Skip to contents

Rounds a vector preserving the rounded sum.

Usage

round_vector(x, digits = 0)

Arguments

x

A vector.

digits

Number of decimal places to be rounded to.

Value

description

Examples

set.seed(4)
x <- (rnorm(5)*10) |> abs()
y <- round_vector(x)
cbind(x, y)
#>              x  y
#> [1,]  2.167549  2
#> [2,]  5.424926  6
#> [3,]  8.911446  9
#> [4,]  5.959806  6
#> [5,] 16.356180 16
round(sum(x)) - sum(y)
#> [1] 0