Repeat an expression multiple times and (optionally) stack the results.
Source:R/repeat_and_stack.R
repeat_and_stack.Rd
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.
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
.
Examples
repeat_and_stack(n = 3, data.frame(x = rexp(2)))
#> x
#> 1 1.7272566
#> 2 4.3115028
#> 3 1.2542130
#> 4 0.7333867
#> 5 0.4364060
#> 6 2.9640214
repeat_and_stack(n = 3, data.frame(x = rexp(2)), stack = FALSE)
#> [[1]]
#> x
#> 1 2.6859047
#> 2 0.5160765
#>
#> [[2]]
#> x
#> 1 0.4349498
#> 2 1.2505684
#>
#> [[3]]
#> x
#> 1 0.04620374
#> 2 0.34424903
#>