On 1/14/08, Jim Price <[EMAIL PROTECTED]> 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/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to