Skip to contents

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)

Arguments

x

Numeric.

target

Numeric.

roundFx

Any of round, floor, or ceiling.

Value

Numeric.

Examples

roundTo(0.73, 0.05)
#> [1] 0.75
roundTo(0.73, 0.1)
#> [1] 0.7
roundTo(0.73, 0.25)
#> [1] 0.75
roundTo(0.73, 0.25, floor)
#> [1] 0.5
roundTo(0.73, 1)
#> [1] 1
roundTo(0.73, 10)
#> [1] 0
roundTo(0.73, 10, ceiling)
#> [1] 10