title: Subset a dataframe with specific condition in R
body: <p>hello I have this df</p>
  <pre><code>        res1 res4 aa1234
  
      1     1    4   IVGG
      2    10   13   RQFP
      3   102  105   TSSV
      4   112  115   LQNA
      5   118  121   EAGT
      6    12   15   FPFL
      7   132  135   RSGG
      8   138  141   SRFP
      9   150  153   PEDQ
      10  151  154   EDQC
      11  155  158   RPNN
      12  165  168   TRRG
      13  171  174   CNGD
      14  172  175   NGDG
      15  174  177   DGGT
      16  181  184   CEGL
      17  195  198   PCGR
      18   20   23   NQGR
      19  205  208   RVAL
      20   32   35   HARF
      21   39   42   AASC
      22   40   43   ASCF
      23   48   51   PGVS
      24   57   60   AYDL
      25   59   62   DLRR
      26   64   67   ERQS
      27   65   68   RQSR
      28   78   81   ENGY
      29    8   11   RPRQ
      30   82   85   DPQQ
      31   83   86   PQQN
      32   86   89   NLND
      33   95   98   LDRE
  </code></pre>
  <p>I want to subset it considering only rows in which res1 are in sequence as i and i &lt;= i+4, as :</p>
  <pre><code>   res1 res4 aa1234
  29    8   11   RPRQ
   6   12   15   FPFL
  21   39   42   AASC
  22   40   43   ASCF
  24   57   60   AYDL
  25   59   62   DLRR
  26   64   67   ERQS
  27   65   68   RQSR
  28   78   81   ENGY
  30   82   85   DPQQ
  31   83   86   PQQN
  32   86   89   NLND
  9   150  153   PEDQ
  10  151  154   EDQC
  11  155  158   RPNN
  13  171  174   CNGD
  14  172  175   NGDG
  15  174  177   DGGT
  </code></pre>
  <p>I tried something woth functions &quot;filter&quot; and &quot;subset&quot; but I didn't got the result expected.</p>
  <p>So in general, I need to have the overlap between two rows in a range (i-i+4) including i+4.</p>
  <p>For example, in this 3 lines there is the overlap between rows [9] and [10] (150-153 overlaps with 151-154), but also row [11] corresponds to res1[10] + 4 (151+4 = 155). So maybe an idea should be to consider res1[i] and check if res1[i+1] is =&lt; res[i].</p>
  <pre><code>9   150  153   PEDQ
  10  151  154   EDQC
  11  155  158   RPNN
  </code></pre>