Skip to contents

If accuracy is omitted, number will be rounded to the nearest order of magnitude IE 145, if fn = min, will round to 100

Usage

round_to(
  ...,
  accuracy = NULL,
  fn = min,
  f = if (identical(fn, min)) {
     floor
 } else {
     ceiling
 },
  na.rm = TRUE
)

Arguments

...

num vectors

accuracy

number to round to; for POSIXct objects, a number of seconds

fn

fun min/max

f

rounding function: floor, ceiling or round

na.rm

a logical indicating whether missing values should be removed.

Value

num

Examples

round_to(runif(10, 5, 10), sample(1:10, 5))
#> [1] 1
round_to(runif(10, 5, 10), sample(1:10, 5), fn = max)
#> [1] 10
round_to(45)
#> [1] 40
round_to(145)
#> [1] 100
round_to(145, fn = max)
#> [1] 200