[R] howto get significant digits for round()

Don MacQueen macq at llnl.gov
Thu May 15 04:53:42 CEST 2008


I must say, I can't deduce, from what you have said, what the desired 
rounding rule is.

The following function does not do what you want, but maybe it's a 
little bit related...

>  rounds
function (x, val = 1)
val * round(x/val)


If
      length = 12.2232
and
      delta-length = 0.4      (delta minus length, that is)
then it must be that
      delta = 11.8232
?

12.2232 rounded to the nearest multiple of 0.4 is 12.4, not 12.2, if 
that's what you meant  by tolerance.

-Don

At 11:31 PM +0200 5/14/08, Jonas Stein wrote:
>i have a table like this of an value and its tolerance
>
>length   delta-length
>12.2232  0.4
>123.422  0.034123
>1234     12
>
>i want to round the value to the significant digits in this way:
>
>my-round(length,delta-length)
>
>12.2   ,  0.4
>123.42 ,  0.03
>1234   ,  12
>
>how can i do this with R?
>
>please CC to email,
>thanks so far,
>
>--
>Jonas Stein <news at jonasstein.de>
>
>______________________________________________
>R-help at 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.


-- 
---------------------------------
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
macq at llnl.gov



More information about the R-help mailing list