rnatural-logarithm

How to convert a number on the log2 scale to natural log


I need to convert a number in the log2 scale (4.6), to the natural scale.

Using Rmpfr in this example (text doesn't work as there is no way to input my data as base = (natural log). I cannot see any other packages that will allow me to do this. I wonder what it is I am missing. Apologies if this is a very simple question; I'm very new to quantitative research.


Solution

  • As pointed out in the comments, there are two ways to do this:

    x1 <- log(2^4.6)
    

    first converts the number back from log2 to the unlogged scale (the value is 24.25), then computes its natural logarithm (3.188).

    The change-of-base formula uses more math, but is slightly more efficient (especially if you compute the value of log2(exp(1)) (or log(2)) once, store it, and re-use it in multiple calculations).

    x2 <- 4.6/log2(exp(1))
    ## this can also be expressed as:
    x3 <- 4.6*log(2)
    stopifnot(all.equal(x1, x2))
    stopifnot(all.equal(x1, x3))