79608768

Date: 2025-05-06 13:08:54
Score: 1
Natty:
Report link

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))
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @lukaA
  • Low reputation (0.5):
Posted by: Mario Reutter