R - factorial() Function
The R factorial() function returns the factorial of a given number.
Syntax
factorial(x)
Parameters
x |
Required. Specify the number. |
Return Value
Returns the factorial of a given number.
Example:
In the example below, factorial() function is used to calculate the factorial of a given number.
cat("3! =", factorial(3), "\n") cat("5! =", factorial(5), "\n") cat("10! =", factorial(10), "\n")
The output of the above code will be:
3! = 6 5! = 120 10! = 3628800
❮ R Math Functions