[R] log10(), floor() combo issue?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon Oct 14 14:32:05 CEST 2002
You will find that a `fuzz', typically 1.0e-7, is added to quantities
before floor() or as.integer() all over R. seq.default() is one example.
For log10(1000) we use log(1000)/log(10), and that is not a ratio of
On Mon, 14 Oct 2002, E.L. Willighagen wrote:
> Hi all,
> in my search for a nice binary2decimal method, I received this nice
> code (thanx to Uwe Ligges):
> bindec <- function(b)
> sum(as.integer(unlist(strsplit(b, ""))) * 2^(floor(log10(b)):0))
> It fails, however, with:
> > bindec(1000)
>  4
> Warning message:
> longer object length
> is not a multiple of shorter object length in:
> as.integer(unlist(strsplit(b, ""))) * 2^(floor(log10(b)):0)
> The reason is the combination of floor() and log10():
> log10(1000) = 3
> ok, but:
> floor(log10(1000)) = 2
> ? Ok, I can live with some floating point inaccuracy, but this seems
> at least a bit strange, and to me troublesome as it makes the bindec()
> method fail...
> I've also tried to force the output of log10(1000) into integer format
> However, with the same disappointing results...
> kind regards,
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help