If you are using tidyverse
, the best way is to use slice
together with rep
:
df <- data.frame(x = 1, y = 1)
slice(df, rep(1, 5))
It is very similar to @lukaA 's answer using rbind
but spares you from having to call df
twice (and from indexing with square brackets).
If you want to duplicate the whole data frame, you can take use of n()
, too:
df <- data.frame(x = 1:3, y = 1:3)
slice(df, rep(1:n(), 2))