title: FItering rows with matching values
body: <p>I have a dataset of like the following one.
  With subjects that join groups over time</p>
  
  <pre><code>
  df &lt;- data.frame("group" = c("A", "A", "A+1","A+1", "A+1", "B","B+1","B+1"), 
                   "id" = c("id1", "id2", "id1", "id2", "id3", "id5","id5","id1"), 
                   "time" = c(1,1,3,3,3,2,5,5),
                   "Val" = c(10,10,10,10,10,12,12,12),
                    "groupid" = c("A", "A", "A","A", "A", "B","B","B"))
  
  </code></pre>
  
  <p>My final aim is to add all of the values grouping by id. </p>
  
  <p>My problem is that as a new subject join groups, for instance, group "A" becomes Group "A+1" when subject "id3" joins at time 3, all of my observations are duplicated ("A+1" include "id1" and "id2". Hence I cannot do my sum.  </p>
  
  <p>In sum, I would like to remove duplicated "ids" based on "Group id" identifiers.<br>
  the final df should look like this</p>
  
  <pre><code>
  final &lt;- data.frame("group" = c("A", "A", "A+1", "B","B+1"), 
                   "id" = c("id1", "id2", "id3", "id5","id1"), 
                   "time" = c(1,1,3,2,5),
                   "Val" = c(10,10,10,12,12),
                   "groupid" = c("A", "A", "A", "B","B"))
  </code></pre>
  
  <p>I thank you a lot in advance for your help</p>
  
  <hr>
  
  <p>Follow up question</p>
  
  <p>I also have the opposite case whereby some subject leave the group over time. The dataset looks something like this:</p>
  
  <pre><code>df2 &lt;- data.frame("group" = c("A", "A", "A","A_1", "A_1", "B","B","B_1"), 
                   "id" = c("id1", "id2", "id3", "id2", "id3", "id5","id1","id1"), 
                   "time" = c(1,1,1,3,3,2,2,5),
                   "Val" = c(10,10,10,10,10,12,12,12),
                   "groupid" = c("A", "A", "A","A", "A", "B","B","B"))
  </code></pre>
  
  <p>In this case, one subject "id1" leaves the "group A" that becomes group "A_1", where only "id2" and "id3" are members. Similarly "id5" leaves group B that becomes "B_1" with only id1 as a member. </p>
  
  <p>What I would like to have in the final dataset is an opposite type of groups identification that should look something like this </p>
  
  <pre><code>final2 &lt;- data.frame("group" = c("A", "A", "A","A_1", "B","B","B_1"), 
                       "id" = c("id1", "id2", "id3", "id1", "id5","id1","id5"), 
                       "time" = c(1,1,1,3,2,2,5),
                       "Val" = c(10,10,10,10,12,12,12),
                       "groupid" = c("A", "A", "A","A", "B","B","B"))
  </code></pre>
  
  <p>Whereby "A_1" and "B_1" only indicate the subjects, "id1" and "id5" respectively, that has left the group, rather than the remaining ones. </p>
  
  <p>Any suggestions on this approach? </p>
  
  <p>I thank you in advance for your help</p>