[R] sequence with start and stop positions

Chris Oldmeadow c.oldmeadow at student.qut.edu.au
Tue Aug 26 06:41:42 CEST 2008


Hi,

I have a vector of start positions, and another vector of stop positions,

eg start<-c(1,20,50)
     stop<-c(7,25,53)

Is there a quick way to create a sequence from these vectors?

new<-c(1,2,3,4,5,6,7,20,21,22,23,24,25,50,51,52,53)

the way Im doing it at the moment is

pos<-seq(start[1],stop[1])

for (i in 2:length(start)){
  new<-seq(start[i],stop[i])
  pos<-c(pos,new)
}

This works on small data, but its very inefficient on large vectors, and 
is taking forever!

Anybody no a better way?

many thanks,
Chris



More information about the R-help mailing list