R Tutorial R Charts & Graphs R Statistics R References

R - lgamma() Function



The R lgamma() function returns the natural logarithm of the absolute value of gamma function (log gamma function) of the argument. The log gamma function of x is defined as:

lgamma
Log-gamma Function

Syntax

lgamma(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns natural logarithm of the absolute value of gamma function of the argument.

Example:

The example below shows the usage of lgamma() function.

#operating on single element atomic vector
print(lgamma(0.1))
print(lgamma(0.5))
print(lgamma(1.5))

cat("\nOperating on vector\n")
#operating on vector
v <- c(4.1, 5.1, 6.1)
print(lgamma(v))

cat("\nOperating on matrix\n")
#operating on matrix
m <- matrix(c(1.5, 2.5, 3.5, 4.5, 5.5, NaN), nrow=2)
print(lgamma(m))

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

The output of the above code will be:

[1] 2.252713
[1] 0.5723649
[1] -0.1207822

Operating on vector
[1] 1.918777 3.329764 4.959005

Operating on matrix
           [,1]     [,2]     [,3]
[1,] -0.1207822 1.200974 3.957814
[2,]  0.2846829 2.453737      NaN

Operating on first column of matrix
[1] -0.1207822  0.2846829

❮ R Math Functions

5