Possible Duplicate:
R round to nearest .5 or .1
How do I round to 1, 1.5, 2 etc instead of 1, 2 or 1.1, 1.2, 1.3 in R?
if I want to round a number with some digits after comma
a <- 2.1357
I can use
round(a, 1)
to obtain 2.1 as result.
Now let I have an array of numbers like
b <- rnorm(n = 10, mean = .5, sd = .1)
> b
[1] 0.5554950 0.4527671 0.5217543 0.6137458 0.6023219 0.7045009 0.5140363 0.5312920
[9] 0.5841152 0.4492901
If I want to round those numbers in order to make them multiples of 0.1, it’s enough to input
round(b, 1)
Now my question: what if I would like to round them in order to make the multiples of… 0.2? Or 0.3? Or 0.25… an so on?
Thanks,
gets you