[R] Extracting Sequence Data from a Vector

Eric Vander Wal eric.vanderwal at usask.ca
Wed Jun 10 19:28:09 CEST 2009


Thanks in advance.
I have a vector of numbers which contain sections that are sequences 
which increase by a value of 1 followed by a gap in the data and then 
another sequence occurs, etc:

x<-c(1:3, 6: 7, 10:13)

 From the vector I need to extract 2 items of information A) the first 
number in the sequence (e.g., 1, 6, 10) and B) how many observations 
were in each  sequence section (e.g., 3, 2, 4).

v1   v2
1      3
6      2
10    4

It seems simple, but my R skills are still in their infancy so I very 
much appreciate the help.
Eric

-- 
Eric Vander Wal
Ph.D. Candidate
University of Saskatchewan, Department of Biology,
112 Science Place, Saskatoon, SK., S7N 5E2

"Pluralitas non est ponenda sine neccesitate"




More information about the R-help mailing list