This help topic is for R version 1.5.0. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/base/html/Log.html
log {base}R Documentation

Logarithms and Exponentials

Description

log computes natural logarithms, log10 computes common (i.e., base 10) logarithms, and log2 computes binary (i.e., base 2) logarithms. The general form logb(x, base) computes logarithms with base base (log10 and log2 are only special cases).

log1p(x) computes \log(1+x) accurately also for |x| \ll 1 (and less accurately when x \approx -1).

exp computes the exponential function.

expm1(x) computes \exp(x) - 1 accurately also for |x| \ll 1.

Usage

log(x, base = exp(1))
logb(x, base = exp(1))
log10(x)
log2(x)
exp(x)
expm1(x)
log1p(x)

Arguments

x

a numeric or complex vector.

base

positive number. The base with respect to which logarithms are computed. Defaults to e=exp(1).

Value

A vector of the same length as x containing the transformed values. log(0) gives -Inf (when available).

Note

log and logb are the same thing in R, but logb is preferred if base is specified, for S-PLUS compatibility.

See Also

Trig, sqrt, Arithmetic.

Examples

log(exp(3))
all.equal(log(1:10), log(1:10, exp(1)))
log10(30) == log(30, 10)
log10(1e7)# = 7
log2(2^pi) == 2^log2(pi)
Mod(pi - log(exp(pi*1i)) / 1i) < .Machine$double.eps
Mod(1+exp(pi*1i)) < .Machine$double.eps

x <- 10^-(1+2*1:9)
cbind(x, log(1+x), log1p(x), exp(x)-1, expm1(x))

[Package base version 1.5.0 ]