Learn R Programming

omnibus (version 1.2.12)

roundTo: Round to nearest target value

Description

This function rounds a value to a nearest "target" value (e.g., you could round 0.72 to the nearest 0.25, or 0.75).

Usage

roundTo(x, target, roundFx = round)

Value

Numeric.

Arguments

x

Numeric.

target

Numeric.

roundFx

Any of round, floor, or ceiling.

Examples

Run this code
roundTo(0.73, 0.05)
roundTo(0.73, 0.1)
roundTo(0.73, 0.25)
roundTo(0.73, 0.25, floor)
roundTo(0.73, 1)
roundTo(0.73, 10)
roundTo(0.73, 10, ceiling)

Run the code above in your browser using DataLab