Skip to content
Related Articles

Related Articles

Calculate Factorial of a value in R Programming – factorial() Function
  • Last Updated : 01 Jun, 2020

R Language offers a factorial() function that can compute the factorial of a number without writing the whole code for computing factorial.

Syntax: factorial(x)

Parameters:
x: The number whose factorial has to be computed.

Returns: The factorial of desired number.

Example 1:






# R program to calculate factorial value 
    
# Using factorial() method 
answer1 <- factorial(4
answer2 <- factorial(-3)  
answer3 <- factorial(0)
   
print(answer1) 
print(answer2) 
print(answer3) 

Output:

24
NaN
1

Example 2:




# R program to calculate factorial value 
    
# Using factorial() method 
answer1 <- factorial(c(0, 1, 2, 3, 4)) 
  
print(answer1) 

Output:

1  1  2  6 24

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :