R log Function


log() function computes natural logarithms (Ln) for a number or vector. log10 computes common logarithms (Lg).log2 computes binary logarithms (Log2). log(x,b) computes logarithms with base b.

>log(5)     #ln5
[1] 1.609438

>log10(5)    #lg5
[1] 0.69897

>log2(5)    #log25
[1] 2.321928

>log(9,base=3)  #log39 = 2
[1] 2
Note base is the second parameter.


Let's try vector:
>x <- rep(1:12)
>x
 [1]  1  2  3  4  5  6  7  8  9 10 11 12

>log(x)
 [1] 0.0000000 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 1.9459101
 [8] 2.0794415 2.1972246 2.3025851 2.3978953 2.4849066

>log(x,6)
 [1] 0.0000000 0.3868528 0.6131472 0.7737056 0.8982444 1.0000000 1.0860331
 [8] 1.1605584 1.2262944 1.2850972 1.3382908 1.3868528