round_to: Round to a Specified Value

View source: R/rounding.R

round_toR Documentation

Round to a Specified Value

Description

Round to a Specified Value

Usage

round_to(x, accuracy, direction = c("nearest", "up", "down", "random"))

Arguments

x

A numeric value to round.

accuracy

The accuracy with which to round (i.e., round to the nearest accuracy).

direction

The direction to round. nearest (default) will round to the nearest accuracy, up will round up to the nearest accuracy, down will round down to the nearest accuracy, and random will randomly round up or down to the nearest accuracy as described by Matthews & Harel (2011).

Value

A numeric rounded to the specified accuracy.

References

Matthews, G., & Harel, O. (2011). Data confidentiality: A review of methods for statistical disclosure limitation and methods for assessing privacy. Statistics Surveys, 5, 1–29. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1214/11-SS074")}

Examples

round_to(15, accuracy = 7, direction = "nearest")
round_to(15, accuracy = 7, direction = "up")
round_to(20, accuracy = 7, direction = "down")

wjakethompson/wjake documentation built on June 29, 2024, 7:47 a.m.