Re: [R] round to specific intervals

2011-12-01 Thread Michael Kao
Thanks for all the response, I manage to write a small function to complete what I want based on the wonderful helps. iround <- function(x, interval){ ## Round numbers to desired interval ## ## Args: ## x:Numeric vector to be rounded ## interval: The interval th

Re: [R] round to specific intervals

2011-12-01 Thread Duncan Murdoch
On 01/12/2011 10:55 AM, Michael Kao wrote: Dear R users/helpers, I am wondering is there an existing function in which you can round numbers to a set of values. I know you can use 5 * round(x/5) for rounding to the nearest 5 or so, but what if the interval size is not constant. For example: ##

Re: [R] round to specific intervals

2011-12-01 Thread Bert Gunter
?findInterval .. would get you the endpoints and then you could determine which is nearer. Of course in your "example", everything would get "rounded" to 1. -- Bert On Thu, Dec 1, 2011 at 7:55 AM, Michael Kao wrote: > Dear R users/helpers, > > I am wondering is there an existing function in whi

[R] round to specific intervals

2011-12-01 Thread Michael Kao
Dear R users/helpers, I am wondering is there an existing function in which you can round numbers to a set of values. I know you can use 5 * round(x/5) for rounding to the nearest 5 or so, but what if the interval size is not constant. For example: ## Not run test <- rnorm(100) round(test, c