ran_round | R Documentation |
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.
ran_round(x)
x |
( |
An integer vector.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.