R Tutorial R Charts & Graphs R Statistics R References

R - gamma() Function



The R gamma() function returns gamma function of the argument. The gamma function of x is defined as:

tgamma
Gamma Function

Syntax

gamma(x)

Parameters

x Required. Specify column to compute on.

Return Value

Returns gamma function of the argument.

Example:

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

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

cat("\nOperating on vector\n")
#operating on vector
v <- c(4.1, 5.1, 6.1)
print(gamma(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(gamma(m))

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

The output of the above code will be:

[1] 9.513508
[1] 1.772454
[1] 0.8862269

Operating on vector
[1]   6.812623  27.931754 142.451944

Operating on matrix
          [,1]      [,2]     [,3]
[1,] 0.8862269  3.323351 52.34278
[2,] 1.3293404 11.631728      NaN

Operating on first column of matrix
[1] 0.8862269 1.3293404

❮ R Math Functions