R: round with increments larger 1

Asked by At

How to round by increment larger than 1? Acctualy, I need the next "ceiling" in steps of 5. Example:

ceiling(c(2.5, 6, 9.9, 10, 11, 14, 15), inc = 5)   #not working
> 5  10  10  15  15  15  20

I tried ceiling(), round() and signif() but I could not figure it out. It's probably a repetition but my research always leads me to increments smaler than 1.

Thanks in advanced!

1 Answers

0
Vishal Jaiswal On Best Solutions

This should work for you

a=c(2.5, 6, 9.9, 10, 11, 14, 15)
fiver=function(x)
{
  multiplier=floor(x/5)+1
  return(5*(multiplier))
}

fiver(a)

[1] 5 10 10 15 15 15 20