round: Override R Rounding

Description Usage Arguments Examples

View source: R/round.R

Description

Rounds like SAS or Excel with faced with .5

Usage

1
round(x, digits = 0)

Arguments

x

the number to round

digits

how many decimal points do you want?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Left to it's own devices, R will always round to the even digit. Most
# people don't expect this and tools like Excel and SAS will not behave
# in this way. For example, here is what round will do when faced with
# a vector of numbers that end in .5

round(c(1.5, 2.5, 3.5, 4.5, 5.5, 6.5))

[1] 2 2 4 4 6 6

# You probably expect this to be 2, 3, 4, 5, 6, 7 and that is indeed
# what would have happened in Excel. But, R rounding is based on IEC 60559.
# This stinks, so in cohortr round is overriden. When you import the
# cohortr library this is what the behavior of round is:

library(cohortr)

round(c(1.5, 2.5, 3.5, 4.5, 5.5, 6.5))

[1] 2 3 4 5 6 7

mattjcamp/cohortr documentation built on May 21, 2019, 1:24 p.m.