[R] patterns in numeric vector

C Lin baccts at hotmail.com
Mon Jun 20 20:58:08 CEST 2016


Hello,

Can someone help me with this?

I am trying to find the start and end positions in a vector where numbers less than x is surrounded by number(s) greater than x.
 For example:
 try = c(7,223,42,55,30,25,61,5,70)
 x=40

 The desired output would be:

> loc
    start end
1     5      6
2     8       8

So the numbers I am interested in finding is: 30, 25 and the start= 5 and end = 6
Also, 5 with the start=8 and end = 8
  
Thank you in advance for your help.



More information about the R-help mailing list