log(x)
function computes natural logarithms (Ln) for a number or vector x by default. If the base is specified, log(x,b)
computes logarithms with base b.
log10
computes common logarithms (Lg). log2
computes binary logarithms (Log2).
log(x, base = exp(1))
>log(5)#ln5 [1] 1.609438 > log(13.27)#ln(13.27) [1] 2.585506
The
>log(9,base=3)#log39 = 2
>log10(5)#lg5
[1] 0.69897
>log2(5)#log25
[1] 2.321928
[1] 2
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
Let's plot the log() function:
> x <- seq(0,100,by=0.1) > plot(x,log(x),typ="l",col="blue")