Message-ID: <4ED7A955.7040205@gmail.com>
Date: 2011-12-01T16:20:37Z
From: Duncan Murdoch
Subject: round to specific intervals
In-Reply-To: <4ED7A369.4050206@gmail.com>
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:
> ## 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.
I think you could put together such a thing using cut().
Duncan Murdoch