Learn R Programming

simhelpers (version 0.3.1)

repeat_and_stack: Repeat an expression multiple times and (optionally) stack the results.

Description

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.

Usage

repeat_and_stack(n, expr, stack = TRUE)

Value

If stack = TRUE (the default), the results of each evaluation of expr will be stacked together using rbind. If stack = FALSE, a list of length n with entries corresponding to the output of each replication of expr.

Arguments

n

Number of times to repeat the expression

expr

An expression to be evaluated.

stack

Logical value indicating whether to organize the results into a data.frame.

Examples

Run this code
repeat_and_stack(n = 3, data.frame(x = rexp(2)))

repeat_and_stack(n = 3, data.frame(x = rexp(2)), stack = FALSE)

Run the code above in your browser using DataLab