round2: Round up from .5

View source: R/webexercises_fns.R

round2R Documentation

Round up from .5

Description

Round up from .5

Usage

round2(x, digits = 0)

Arguments

x

A vector of numeric values.

digits

Integer indicating the number of decimal places ('round') or significant digits ('signif') to be used.

Details

Implements rounding using the "round up from .5" rule, which is more conventional than the "round to even" rule implemented by R's built-in round function. This implementation was taken from https://stackoverflow.com/a/12688836.

Value

A vector of rounded numeric values.

Examples

round2(c(2, 2.5))

# compare to:
round(c(2, 2.5))

webexercises documentation built on May 31, 2023, 8:16 p.m.