[R] sequence with start and stop positions

Christos Hatzis christos at nuverabio.com
Tue Aug 26 08:01:26 CEST 2008


Try:

> unlist(mapply(seq, c(1,20,50), c(7,25,53)))
 [1]  1  2  3  4  5  6  7 20 21 22 23 24 25 50 51 52 53

-Christos 

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Chris Oldmeadow
> Sent: Tuesday, August 26, 2008 12:42 AM
> To: r-help at r-project.org
> Subject: [R] sequence with start and stop positions
> 
> 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
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
>



More information about the R-help mailing list