Re: [R] Extracting Sequence Data from a Vector

2009-06-10 Thread David Winsemius
On Jun 10, 2009, at 1:28 PM, Eric Vander Wal wrote: 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

Re: [R] Extracting Sequence Data from a Vector

2009-06-10 Thread baptiste auguie
jim holtman wrote: try this: Oh well, i spent the time writing this so i might as well post my (almost identical) solution, x<-c(1:3, 6: 7, 10:13) breaks = c(TRUE, diff(x) != 1) data.frame(start = x[breaks], length = tabulate(cumsum(breaks))) Hoping this works, baptiste x [1

Re: [R] Extracting Sequence Data from a Vector

2009-06-10 Thread jim holtman
try this: > x [1] 1 2 3 6 7 10 11 12 13 > # find breaks > breaks <- c(FALSE, diff(x) != 1) > # now create matrix with groupings (just for visual) > z <- data.frame(x, cumsum(breaks)) > # create list with first element of each seq and the length > t(sapply(split(z, z[,2]), function(b) c(b[1,1]

[R] Extracting Sequence Data from a Vector

2009-06-10 Thread Eric Vander Wal
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 t