time<-c(10,20)
d<-NULL
for ( i in seq(length(time)))
d<-c(d,seq(0,(time[i]-1)))
d
When time<-c(3000,4000,2000,...,5000) and the length of time is 1000, the procedure is very slow.
Is there a faster way generating the sequence without looping?
Thanks for your help.
Try
d <- unlist(lapply(time,function(i)seq.int(0,i-1)))On a sidenote, one thing that slows down the whole thing, is the fact that you grow the vector within the loop.
Edit : added timing for other solutions as well