Evaluate expression n times then combine results into a data frame
rdply(.n, .expr, .progress = "none", .id = NA)number of times to evaluate the expression
expression to evaluate
name of the progress bar to use, see
create_progress_bar
name of the index column. Pass NULL to avoid creation of
the index column. For compatibility, omit this argument or pass NA
to use ".n" as column name.
a data frame
This function runs an expression multiple times, and combines the result into
a data frame. If there are no results, then this function returns a data
frame with zero rows and columns (data.frame()). This function is
equivalent to replicate, but will always return results as a
data frame.
Hadley Wickham (2011). The Split-Apply-Combine Strategy for Data Analysis. Journal of Statistical Software, 40(1), 1-29. https://www.jstatsoft.org/v40/i01/.
rdply(20, mean(runif(100)))
#> .n V1
#> 1 1 0.4795744
#> 2 2 0.4619230
#> 3 3 0.4937163
#> 4 4 0.5056349
#> 5 5 0.4755529
#> 6 6 0.4724123
#> 7 7 0.5372040
#> 8 8 0.5301065
#> 9 9 0.5131290
#> 10 10 0.5444707
#> 11 11 0.5657078
#> 12 12 0.4684942
#> 13 13 0.5239426
#> 14 14 0.5541316
#> 15 15 0.5258364
#> 16 16 0.5119269
#> 17 17 0.4832072
#> 18 18 0.5097692
#> 19 19 0.4745947
#> 20 20 0.5303042
rdply(20, each(mean, var)(runif(100)))
#> .n mean var
#> 1 1 0.4873160 0.08598864
#> 2 2 0.5221509 0.09519466
#> 3 3 0.4947220 0.08025103
#> 4 4 0.5368994 0.08335525
#> 5 5 0.4739039 0.08891457
#> 6 6 0.5091936 0.07533008
#> 7 7 0.4926832 0.08071563
#> 8 8 0.4969253 0.08208359
#> 9 9 0.5180824 0.09649493
#> 10 10 0.5293319 0.09211816
#> 11 11 0.5258403 0.09443793
#> 12 12 0.4434285 0.07515195
#> 13 13 0.5472506 0.09163580
#> 14 14 0.4875347 0.07910611
#> 15 15 0.4781630 0.08854618
#> 16 16 0.4916634 0.08125938
#> 17 17 0.5343236 0.07783850
#> 18 18 0.5042167 0.08035243
#> 19 19 0.5101281 0.07934224
#> 20 20 0.5199815 0.07614262
rdply(20, data.frame(x = runif(2)))
#> .n x
#> 1 1 0.140353269
#> 2 1 0.545322403
#> 3 2 0.904697092
#> 4 2 0.253702644
#> 5 3 0.602473737
#> 6 3 0.441347882
#> 7 4 0.647197510
#> 8 4 0.394503333
#> 9 5 0.957982466
#> 10 5 0.203466160
#> 11 6 0.292937938
#> 12 6 0.936537911
#> 13 7 0.982041245
#> 14 7 0.479236994
#> 15 8 0.330646341
#> 16 8 0.924491715
#> 17 9 0.715084739
#> 18 9 0.149491671
#> 19 10 0.297409046
#> 20 10 0.389014139
#> 21 11 0.181730398
#> 22 11 0.503558082
#> 23 12 0.972787563
#> 24 12 0.775012026
#> 25 13 0.350684260
#> 26 13 0.474066010
#> 27 14 0.029976892
#> 28 14 0.668548816
#> 29 15 0.818863351
#> 30 15 0.521741578
#> 31 16 0.338766052
#> 32 16 0.625411691
#> 33 17 0.320346392
#> 34 17 0.701813391
#> 35 18 0.004481501
#> 36 18 0.110020100
#> 37 19 0.339631328
#> 38 19 0.177673390
#> 39 20 0.470992930
#> 40 20 0.784546703