[R] round to specific intervals
gunter.berton at gene.com
Thu Dec 1 17:17:02 CET 2011
.. would get you the endpoints and then you could determine which is nearer.
Of course in your "example", everything would get "rounded" to 1.
On Thu, Dec 1, 2011 at 7:55 AM, Michael Kao <mkao006rmail at gmail.com> 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:
> ## Not run
> test <- rnorm(100)
> round(test, c(1, 5, 10, 20, 50))
> so that the test is rounded to the closest value in the vector.
> Thanks for the help.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help