Skip to content
Prev 86237 / 398502 Next

Creating multiple copies of rows in data frames

Eric Archer wrote:
As you mentioned, ?rep should be sufficient:

in.df <- data.frame(x = LETTERS[1:3], y = 1:3)
out.df <- in.df[rep(seq(nrow(in.df)), in.df$y), ]

Then if you want to re-name the row.names

row.names(out.df) <- seq(nrow(out.df))

--sundar