title: subset a data frame using dplyr in R
body: <p>using R I'm trying to filter my data frame according to some arguments. </p>
  
  <p>Here is the data frame: </p>
  
  <pre><code>Groups_name  col1   col2
  group1       3       4
  group1       1       1
  group1       1       1
  group2       1       1
  group3       3       7
  group3       1       1
  group4       3       3
  group4       1       1
  </code></pre>
  
  <p>and by group I want to only keep groups that contain at least one row where the <code>col1 &gt; 1</code> and where <code>col1 == col2</code> or <code>col1 == col2+-2</code> </p>
  
  <p>Here I should get: </p>
  
  <pre><code>Groups_name  col1   col2
  group1       3      4
  group1       1      1
  group1       1      1
  group4       3      3
  group4       1      1
  </code></pre>
  
  <p>as you can see I kept the <code>group1</code> because the in the first row, the <code>col1 &gt;1</code> and <code>col1 (3) = col2 +1 (4)</code> 
  I also keep <code>group 3</code> because the <code>col1 &gt;1</code> and <code>col1 (3) == col2  (3)</code> </p>
  
  <p>but <code>group 1</code> was removed because the <code>col1</code> what <code>not &gt; 1</code></p>
  
  <p>And I also removed the <code>group 3</code> because even if <code>col1 (3) &gt; 1</code>, the <code>col1 (3)</code> is not equal to <code>7 +</code> or <code>- 2</code> (so not equal to <code>5,6,7,8</code> or <code>9</code>) </p>
  
  <p>From now I tried: </p>
  
  <pre><code>tab %&gt;%
    group_by(Groups_name) %&gt;%
    filter(all(col1 == col2,col2-2,col2+2))  %&gt;%
    filter(any(col1 &gt; 1))
  </code></pre>
  
  <p>Thank for your help. </p>