Learn R Programming

stratallo (version 2.2.1)

ran_round: Random Rounding of Numbers

Description

[Stable]

A number \(x\) is rounded to integer \(y\) according to the following rule: $$y = \left\lfloor{x}\right\rfloor + I(u < (x - \left\lfloor{x}\right\rfloor)),$$ where function \(I:\{TRUE, FALSE\} \to \{0, 1\}\), is defined as: $$ I(x) = \begin{cases} 0, & x \text{ is } FALSE \\ 1, & x \text{ is } TRUE, \end{cases} $$ and \(u\) is number that is generated from Uniform(0, 1) distribution.

Usage

ran_round(x)

Value

An integer vector.

Arguments

x

(numeric)
a numeric vector.

Examples

Run this code
x <- c(4.5, 4.1, 4.9)
set.seed(5)
ran_round(x) # 5 4 4
set.seed(6)
ran_round(x) # 4 4 5

Run the code above in your browser using DataLab