Skip to contents

Round numeric vector conditionaly

Usage

round_conditionaly(
  vec,
  cond = cbind(c(1e-05, 5), c(0.001, 3), c(0.01, 3), c(1, 2), c(10, 1), c(100, 0))
)

Arguments

vec

a numeric vector

cond

: a matrix of 2 row an n column with the first row defining the condition and the second row defining the number to round. cond is order in decreasing order of the 1 row internally. Thus the order in cond rows is not important

Value

a numeric vector of the same length as vec

Author

Adrien Taudière

Examples

round_conditionaly(vec = c(1000.27890, 10.87988, 1.769869, 0.99796, 0.000179))
#> [1] 1000.27890   10.87988    1.76987    0.99796    0.00018
round_conditionaly(
  vec = c(1000.27890, 0.000179, 10e-11),
  cond = cbind(c(10e-5, 5), c(10, 2))
)
#> [1] 1.000279e+03 1.800000e-04 1.000000e-10