Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

signif_half_up

Round a numeric vector to the specified number of significant digits; halves will be rounded up.


Description

In base R signif(), halves are rounded to even, e.g., signif(11.5, 2) and signif(12.5, 2) are both rounded to 12. This function rounds 12.5 to 13 (assuming digits = 2). Negative halves are rounded away from zero, e.g., signif(-2.5, 1) is rounded to -3.

This may skew subsequent statistical analysis of the data, but may be desirable in certain contexts. This function is implemented from https://stackoverflow.com/a/1581007/; see that question and comments for discussion of this issue.

Usage

signif_half_up(x, digits = 6)

Arguments

x

a numeric vector to round.

digits

integer indicating the number of significant digits to be used.

Examples

signif_half_up(12.5, 2)
signif_half_up(1.125, 3)
signif_half_up(-2.5, 1) # negatives get rounded away from zero

janitor

Simple Tools for Examining and Cleaning Dirty Data

v2.1.0
MIT + file LICENSE
Authors
Sam Firke [aut, cre], Bill Denney [ctb], Chris Haid [ctb], Ryan Knight [ctb], Malte Grosser [ctb], Jonathan Zadra [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.