I have a data.frame
:
set.seed(1)
short.df <- data.frame(id=letters[1:10],name=LETTERS[1:10])
And I want to replicate each row by a number of times given by a vector whose length equals nrow(short.df)
:
lengths <- c(sample(10000,10,replace=F))
This takes too long for my real data size:
long.df <- do.call(rbind,lapply(1:length(lengths),function(x) data.frame(id=rep(short.df$id,lengths[x]),name=rep(short.df$name,lengths[x]))))
Any way to do it faster?