title: R data.table: Filter for rows by condition in multiple variables
body: <p>I have a filter problem with the following data.table and really hope that someone can help me with that. I am not sure if there is an easy way of doing that and hope that it is not too much to ask for. So this is my problem:</p>
  
  <pre><code>A   B   C   Area
  aa  M+H 1   127427
  aa  M+H 2   204051.5
  aa  M+Na    1   6855539.48777
  aa  M+Na    2   6469689
  bb  M+H 1   15330650
  bb  M+H 2   214221
  bb  M+H 3   11357158
  bb  M+K 1   2140221
  bb  M+K 2   61715568
  </code></pre>
  
  <p>For each group A B (aa M+H, aa M+Na, bb M+H, bb M+K) all rows with a value C > 1 should be filtered out if their Area value is higher than in the row with the same A B combination and a C value 1 (each A B C combination exists only once in the table). After that step the following rows should be left:</p>
  
  <pre><code>A   B   C   Area
  aa  M+H 1   127427
  aa  M+Na    1   6855539.48777
  aa  M+Na    2   6469689
  bb  M+H 1   15330650
  bb  M+H 2   214221
  bb  M+H 3   11357158
  bb  M+K 1   2140221
  </code></pre>
  
  <p>and after that i would like to filter out all rows which are in the same A C group (aa 1, aa 2, bb 1, bb2) but with a higher Area value than in the row with an "M+H" as B value. So this should be left:</p>
  
  <pre><code>A   B   C   Area
  aa  M+H 1   127427
  aa  M+Na    2   6469689
  bb  M+H 1   15330650
  bb  M+H 2   214221
  bb  M+H 3   11357158
  bb  M+K 1   2140221
  </code></pre>
  
  <p>And in the end get rid of all A B groups (aa M+H, aa M+Na, bb M+H, bb M+K) that do not one row with a value of 1 in C left. So there should only be:</p>
  
  <pre><code>A   B   C   Area
  aa  M+H 1   127427
  bb  M+H 1   15330650
  bb  M+H 2   214221
  bb  M+H 3   11357158
  bb  M+K 1   2140221
  </code></pre>
  
  <p>I was trying to get it done using data.table but if someone tells me that dplyr is much better for it I would also be happy for a solution there. Anyway thank you a lot for your time and effort!</p>
  
  <p>Yasel</p>