Calculate Factorial of a value in R Programming – factorial() Function

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