EDIT: Updated to the best modern R answer.
You can use replicate() and then rbind result. Line names are automatically changed to run from 1: nrows.
d <- data.frame(a = c(1,2,3),b = c(1,2,3)) n <- 3 do.call("rbind", replicate(n, d, simplify = FALSE))
A more traditional way is to use indexing, but here changing the name of the string is not entirely accurate (but more informative):
d[rep(seq_len(nrow(d)), n), ]
Here is the improvement on the above, the first two using purrr functional programming, idiomatic purrr:
purrr::map_dfr(seq_len(3), ~d)
and less idiomatic purrs (identical result, albeit more awkward):
purrr::map_dfr(seq_len(3), function(x) d)
and finally, using indexing, not a list, apply using dplyr :
d %>% slice(rep(row_number(), 3))
mdsumner Jan 6 '12 at 5:23 2012-01-06 05:23
source share