[R] Ceiling to the nearest ten?
hadley wickham
h.wickham at gmail.com
Mon Jan 14 19:06:10 CET 2008
On 1/14/08, Jim Price <price_ja at hotmail.com> wrote:
>
> A suggestion for a family of such functions:
>
>
> ceilGenerator <- function(num)
> function(x) num * ceiling(x / num)
>
>
> ceil10 <- ceilGenerator(10)
> ceil20 <- ceilGenerator(20)
>
>
> ceil10(1:10 * 4)
> ceil20(1:10 * 4)
libraray(reshape)
round_any(100, 40, floor)
round_any(100, 40, ceiling)
round_any(101, 40)
# in reshape package
round_any <- function (x, accuracy, f = round) {
f(x/accuracy) * accuracy
}
which is a pretty similar idea.
Hadley
--
http://had.co.nz/
More information about the R-help
mailing list