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
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
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]
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
4 matches
Mail list logo