View source: R/repeat_and_stack.R
| repeat_and_stack | R Documentation |
Repeat an expression (usually involving random number
generation) multiple times. Optionally, organize the results into a
data.frame that stacks the output from all replications of the
expression.
repeat_and_stack(n, expr, id = NULL, stack = TRUE)
n |
Number of times to repeat the expression |
expr |
An expression to be evaluated. |
id |
Character string to use for creating a variable with a unique
identifier for each repetition. If set to |
stack |
Logical value indicating whether to organize the results into a
|
If stack = TRUE (the default), the results of each evaluation
of expr will be stacked together using rbind and a unique identifier will be stored in the variable id (if specified). If stack
= FALSE, a list of length n with entries corresponding to the
output of each replication of expr, with names corresponding to the unique identifier (if specified)
repeat_and_stack(n = 3, data.frame(x = rexp(2)))
repeat_and_stack(n = 3, data.frame(x = rexp(2)), id = "ID")
repeat_and_stack(n = 3, data.frame(x = rexp(2)), stack = FALSE)
repeat_and_stack(n = 3, data.frame(x = rexp(2)), id = "ID", stack = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.