R Tutorial R Charts & Graphs R Statistics R References

R - expm1() Function



The R expm1() function returns e raised to the power of specified number minus 1, i.e., ex-1. Please note that e is the base of the natural system of logarithms, and its value is approximately 2.718282. In special cases it returns the following:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is -1.0.
  • If the argument is zero, then the result is a zero.

Syntax

expm1(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns e raised to the power of specified number minus 1, i.e., ex-1.

Example:

In the example below, expm1() function is used to calculate e raised to the power of specified number minus one.

#operating on single element atomic vector
print(expm1(0))
print(expm1(0.5))
print(expm1(1))

cat("\nOperating on vector\n")
#operating on vector
v <- c(4, 5, 6)
print(expm1(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(1, 2, 3, 4, Inf, NaN), nrow=2)
print(expm1(m))

cat("\nOperating on first column of matrix\n")
#operating on first column of matrix
print(expm1(m[,1]))

The output of the above code will be:

[1] 0
[1] 0.6487213
[1] 1.718282

Operating on vector
[1]  53.59815 147.41316 402.42879

Operating on matrix
         [,1]     [,2] [,3]
[1,] 1.718282 19.08554  Inf
[2,] 6.389056 53.59815  NaN

Operating on first column of matrix
[1] 1.718282 6.389056

❮ R Math Functions