round_trunc: Round at 0.5 toward integer with highest absolute value

View source: R/utilities.R

round_truncR Documentation

Round at 0.5 toward integer with highest absolute value

Description

In normal R rounding, if the first digit to be dropped is exactly 5, R uses the standard programming convention of rounding to the nearest even number. This can have some annoying effects.

This function rounds numbers to the nearest integer, but always rounds to the integer with the highest absolute value when the first digit to be dropped is exactly 5, similar to rounding in usual mathematical contexts.

Usage

round_trunc(x, digits = 0)

Arguments

x

A number.

digits

Number of digits to round to. Default is 0

Value

An integer.

Examples

# If the first digit to be dropped is exactly 5, round_trunc() will round to
# integer with the highest absolute value.
round_trunc(0.5)
round_trunc(-0.5)

pepfar-datim/datapackr documentation built on April 14, 2024, 10:35 p.m.