i need to repeat same row of data frame for n number of times and row bind them to new data frame.
I can easily do it using for loop, but it has more computational time. Can some one help me this doing using any of apply functions.
Below one is the prototype of my code.
testdata<-data.table(v1=sample(1000),v2=sample(1000),v3=sample(1000),v4=as.integer(runif(1000,1,10)))## Sample data
testdata1<-data.table(v1=NA,v2=NA,v3=NA,v4=NA)##creating empty data frame
for(i in 1:nrow(testdata)){
temp<-testdata[i,][rep(seq_len(nrow(testdata[i,])), each=testdata$v4[i]),]
testdata1<-rbind(temp,testdata1)
}
