title: How to remove row based on condition of row above or below
body: <p>I have a dataframe as follows:</p>
  
  <pre><code>     chr   leftPos        ZScore1    ZScore2    ZScore3    ZScore4
        1     24352           34         43          19         43
        1     53534           2          1           -1         -9
        2      34            -15         7           -9         -18
        3     3443           -100        -4          4          -9
        3     3445           -100        -1          6          -1
        3     3667            5          -5          9           5
        3      7882          -8          -9          1           3
  </code></pre>
  
  <p>I would like to only keep those rows which have the same chr and have adjacent columns with the ZScore going in the same direction. In other words a row should remain if the row before or after for that chr has the same sign (positive or negative). I would like this to run for all columns with ZS in the column name so that the output ends up just being a number of rows that fulfil the criteria for each row.</p>
  
  <p>For one column the code should result in:</p>
  
  <pre><code>     chr   leftPos         ZScore
        1     24352           34
        1     53534           2
        3     3443           -100
        3     3445           -100
  </code></pre>
  
  <p>but the final output should look like</p>
  
  <pre><code>         ZScore1    ZScore2    ZScore3    ZScore4
  nrow        4         6          4          4
  
  
   I have tried bits of code but Im not even really sure how to approach this.
  </code></pre>
  
  <p>I guess I would group by chr and then see if the row above was the same positive or negative as the current row and then see if the row below was the same direction as the current row. Then move to the next row for that chr.</p>