The factorial()
function in R
returns the factorial of a positive integer.
A factorial is a product of that positive integer and all the integers below it until 1.
Figure 1 below shows the mathematical representation of the factorial()
function and its corresponding representation in R
.
factorial(integer)
This function requires a positive integer whose factorial is to be calculated.
factorial()
returns the factorial of the positive integer sent as a parameter.
In the case of a
negative value
, awarning
message is displayed along withNaN
.
The following example shows how we can use the factorial()
function in R
.
#example a <- factorial(6); print(paste0("factorial(6): ", a)) b <- factorial(4); print(paste0("factorial(4): ", b)) c <- factorial(0); print(paste0("factorial(0): ", c))
RELATED TAGS
CONTRIBUTOR
View all Courses