z <- rle(VI<1) gets you most of the way there. ?rle will tell you what z is so that you can then use it to go the rest of the way.
-- Bert On Tue, Aug 21, 2012 at 10:54 AM, inti luna <ilunal...@gmail.com> wrote: > Hello, > > I have 2 variable: one is an "id" sequence from 1:1000 and the other is > variable with real values "VI" from -15.0 to 20.0 and I want to detect id > values that have indicator values less than a certain threshold, for > example (x=1) BUT that are in sequence equal or longer than 5. > > For instance, in the following column I want to recognize the sequence from > "id" 4 to 8 that are values with a "VI" values lower than 1 in a sequence > of 5, and not the id values 1 and 2 which are values with VI lower than my > threshold but the sequence is lower than 5. > > id VI > > 1 -10 > 2 -4 > 3 5 > 4 -2 > 5 -5 > 6 -3 > 7 -2 > 8 -1 > 9 4 > 10 8 > > Any help would be appreciated! > > Inti > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm ______________________________________________ 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.