Hi, How can I round up and down to the nearest hundredth example: x <- 0.18 how do I round down to 0.15? how do I round down to 0.20? -- View this message in context: http://r.789695.n4.nabble.com/round-up-down-to-nearest-hundredth-tp4629451.html Sent from the R help mailing list archive at Nabble.com.
On Sat, May 12, 2012 at 01:38:16PM -0700, chuck.01 wrote:> Hi, > How can I round up and down to the nearest hundredth > > example: > > x <- 0.18 > how do I round down to 0.15? > how do I round down to 0.20?Hi. Rounding to 0.15 is not to a nearest hundredth, but to a nearest multiple of 0.05. Rounding down and up to a nearest multiple of a unit u can be done as follows x <- 0.18 u <- 0.05 floor(x/u)*u # [1] 0.15 ceiling(x/u)*u # [1] 0.2 Hope this helps. Petr Savicky.