Learn R Programming

stratallo (version 3.0.1)

rounding: Rounding of Numbers

Description

[Experimental]

Usage

round_ran(x)

round_oric(x)

Value

An integer vector.

Arguments

x

(numeric)
numeric vector.

Functions

  • round_ran(): Random rounding of numbers. A number \(x\) is rounded to an integer \(y\) according to the following rule:

    $$y = \left\lfloor x \right\rfloor + I\!\left(u < x - \left\lfloor x \right\rfloor\right),$$ where the indicator function \(I : \{FALSE,\, TRUE\} \to \{0,\, 1\}\) is defined as $$ I(b) := \begin{cases} 0, & b \text{ is } FALSE, \\ 1, & b \text{ is } TRUE, \end{cases} $$ and \(u\) is a random number drawn from the \(\mathrm{Uniform}(0, 1)\) distribution.

  • round_oric(): Optimal rounding under integer constraints, as proposed by Cont;textualstratallo.

References

Contstratallo

Examples

Run this code
x <- c(4.5, 4.1, 4.9)

set.seed(5)
round_ran(x) # 5 4 4

set.seed(6)
round_ran(x) # 4 4 5

round_oric(x) # 4 4 5

Run the code above in your browser using DataLab