function in R Language is used to repeatedly evaluate a function or expression. It is member of **replicate()**`apply`

family in R base package. In this article, we’ll learn syntax and implementation of `replicate()`

function with the help of examples.

Syntax:replicate(n, expr, simplify)

Parameters:

n:represents number of times the expression has to be evaluated

expr:represents expression

simplify:represents logical value. If TRUE, output is represented in vector or matrix form, otherwise in a list form

**Example 1:**

`# Set the seed ` `set.seed` `(10) ` ` ` `# Generate random numbers with mean = 0 and sd = 1 ` `x <- ` `rnorm` `(5, mean = 0, sd = 1) ` ` ` `# Print ` `print` `(x) ` ` ` `# Evaluating it repeatedly ` `r <- ` `replicate` `(n = 3, ` `rnorm` `(5, 0, 1), simplify = ` `FALSE` `) ` ` ` `# Print ` `print` `(r) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513 [[1]] [1] 0.3897943 -1.2080762 -0.3636760 -1.6266727 -0.2564784 [[2]] [1] 1.1017795 0.7557815 -0.2382336 0.9874447 0.7413901 [[3]] [1] 0.08934727 -0.95494386 -0.19515038 0.92552126 0.48297852

**Example 2:**

`# Output to be present as PNG file ` `png` `(file = ` `"replicateGFG.png"` `) ` ` ` `# Set the seed ` `set.seed` `(10) ` ` ` `# Replicate values and create histogram ` `hist` `(` `replicate` `(100, ` `mean` `(` `rexp` `(10)))) ` ` ` `# Saving the file ` `dev.off` `() ` |

*chevron_right*

*filter_none*

**Output:**

## Recommended Posts:

- Replicate elements of vector in R programming - rep() Method
- Evaluate and Quote an Expression in R Programming - bquote() Function
- Evaluate an Expression in R Programming - eval() Function
- Create an Expression in R Programming - expression() Function
- Check if an Object is an Expression in R Programming - is.expression() Function
- Evaluating an Expression in R Programming - with() and within() Function
- Check if a value or a logical expression is TRUE in R Programming - isTRUE() Function
- Modify Data of a Data Frame with an Expression in R Programming - with() Function
- Convert a String to an Expression in R Programming - parse() Function
- Convert an Expression to a String in R Programming - deparse() Function
- Compute Derivative of an Expression in R Programming - deriv() and D() Function
- Check if a Function is a Primitive Function in R Programming - is.primitive() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Apply a Function over a List of elements in R Programming - lapply() Function
- Search the Interval for Minimum and Maximum of the Function in R Programming - optimize() Function
- Compute the Natural Logarithm of the Absolute Value of Gamma Function in R Programming - lgamma() Function
- Compute the Logarithmic Derivative of the gamma Function in R Programming - digamma() Function
- Compute the Second Derivative of the Logarithmic value of the gamma Function in R Programming - trigamma() Function
- Get the List of Arguments of a Function in R Programming - args() Function
- Recursively apply a Function to a List in R Programming - rapply() function

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.