Hi Jim.

jim holtman schrieb:
> If you only want the first sequence, 

Yes, that's true, I forgot to say that!

>> x <- c(-10, -5, 0, 5, 10, 15, 20)
>> y <- c(10, 10, 10, -5, -6, -7, 10)
>> data <- as.matrix( cbind(x, y) )
>> # if you only want the first 'run', then use 'rle' to find it
>> mask <- data[,1] > 0 & data[,2] > min(data[,2])
>> run <- rle(mask)
>> # now either the first or second will be TRUE, so find it
>> offset <- cumsum(c(1, run$lengths))  # off set of the start of sequence
>> index <- if (run$values[1]) 1 else 2
>> new_data <- data[seq(from=offset[index], length=run$lengths[index]),]
>>

Although I'm far from understanding that -- it seems to work very well for
me. Will have a look into it tomorrow ...

Thanks!

Cheers
Martin

______________________________________________
R-help@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.

Reply via email to