Movatterモバイル変換


[0]ホーム

URL:


log {base}R Documentation

Logarithms and Exponentials

Description

log computes logarithms, by default natural logarithms,log10 computes common (i.e., base 10) logarithms, andlog2 computes binary (i.e., base 2) logarithms.The general formlog(x, base) computes logarithms with basebase.

log1p(x) computes\log(1+x) accurately also for|x| \ll 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)log1p(x)exp(x)expm1(x)

Arguments

x

a numeric or complex vector.

base

a positive or complex number: the base with respect to whichlogarithms are computed. Defaults toe=exp(1).

Details

All exceptlogb are generic functions: methods can be definedfor them individually or via theMathgroup generic.

log10 andlog2 are only convenience wrappers, but logsto bases 10 and 2 (whether computedvialog or the wrappers)will be computed more efficiently and accurately where supported by the OS.Methods can be set for them individually (and otherwise methods forlog will be used).

logb is a wrapper forlog for compatibility with S. If(S3 or S4) methods are set forlog they will be dispatched.Do not set S4 methods onlogb itself.

All exceptlog areprimitive functions.

Value

A vector of the same length asx containing the transformedvalues.log(0) gives-Inf, andlog(x) fornegative values ofx isNaN.exp(-Inf) is0.

For complex inputs to the log functions, the value is a complex numberwith imaginary part in the range[-\pi, \pi]: whichend of the range is used might be platform-specific.

S4 methods

exp,expm1,log,log10,log2 andlog1p are S4 generic and are members of theMath group generic.

Note that this means that the S4 generic forlog has asignature with only one argument,x, but thatbase canbe passed to methods (but will not be used for method selection). Onthe other hand, if you only set a method for theMath groupgeneric thenbase argument oflog will be ignored foryour class.

Source

log1p andexpm1 may be taken from the operating system,but if not available there then they are based on the Fortran subroutinedlnrel by W. Fullerton of Los Alamos Scientific Laboratory (seehttps://netlib.org/slatec/fnlib/dlnrel.f) and (for small x) asingle Newton step for the solution oflog1p(y) = xrespectively.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.(forlog,log10 andexp.)

Chambers, J. M. (1998)Programming with Data. A Guide to the S Language.Springer. (forlogb.)

See Also

Trig,sqrt,Arithmetic.

Examples

log(exp(3))log10(1e7) # = 7x <- 10^-(1+2*1:9)cbind(deparse.level=2, # to get nice column names      x, log(1+x), log1p(x), exp(x)-1, expm1(x))

[Packagebase version 4.6.0Index]

[8]ページ先頭

©2009-2025 Movatter.jp