If you only want the first sequence, then this might work: > 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]),] > > new_data x y [1,] 5 -5 [2,] 10 -6 > data x y [1,] -10 10 [2,] -5 10 [3,] 0 10 [4,] 5 -5 [5,] 10 -6 [6,] 15 -7 [7,] 20 10
On Sat, Oct 25, 2008 at 12:33 PM, Martin Ballaschk <[EMAIL PROTECTED]> wrote: > Hi, > > I'm not very experienced with R and struggle with data selection from a long > matrix with two columns. > > I want to cut out the data between x > 0 and min(y). > >> x <- c(-10, -5, 0, 5, 10, 15, 20) >> y <- c(10, 10, 10, -5, -6, -7, 10) >> data <- as.matrix( cbind(x, y) ) > >> data > x y > [1,] -10 10 > [2,] -5 10 > [3,] 0 10 _ > [4,] 5 -5 |-- data interval > [5,] 10 -6 _| to be selected > [6,] 15 -7 > [7,] 20 10 > > > I need that to select the interval between a time 0 and a peak that is the > minimum here to fit that interval via nls() later. > > Can anybody help? I would be very thankful for general hints how to select > data with the help of conditions. > > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.