title: Simple data-manipulation in R
body: <p>@Aniko points out that one way to view my problem is that I need to find the connected components of a graph, where the vertices are called groups and, variables <code>group</code> and <code>nominated_group</code> indicate an edges between those two groups.  My goal is to create a variable <code>parent_Group</code> which indexes the connected components.  Or as I put it before:</p>
  
  <p>I have a dataframe with four variables: <code>ID</code>, <code>group</code>, and <code>nominated_ID</code>, and <code>nominated_Group</code>.  </p>
  
  <p>Consider sister-groups: Groups A and B are sister-groups if there is at least one case in the data where group==A and nominated_group==B, or vice versa.</p>
  
  <p>I would like to create a variable <code>parent_group</code> which takes on a unique value for each set of sister-groups.  In other words, no nominations should occur between cases in different <code>parent_group</code>s.  Making the <code>parent_group</code> sequential numbers seems like a good idea.</p>
  
  <p>Many thanks for the help I already received <a href="https://stackoverflow.com/questions/5924857/loop-to-create-a-new-variable-based-on-other-cases-in-r-very-basic">here</a>!  I can't really contribute here but note that I try to pay it forward at stats.exchange and on wikipedia.</p>
  
  <p>In my fake data, A and B are sister-groups. Either case ID=4 or ID=5 are sufficient to make this true. Each group is also their own sister-group. The goal, the creation of <code>parent_group</code>, should result in one <code>parent_group</code> for all cases in A or B, and another <code>parent_group</code> for group C</p>
  
  <pre><code>df &lt;- data.frame(ID = c(9, 5, 2, 4, 3, 7), 
    group = c("A", "A", "B", "B", "A", "C"),
    nominated_ID = c(9, 8, 4, 9, 2, 7)     )
  
  df$nominated_group &lt;- with(df, group[match(nominated_ID, ID)])
  
  df
  
    ID group nominated_ID nominated_group
  1  9     A            9               A
  2  5     A            8            &lt;NA&gt;
  3  2     B            4               B
  4  4     B            9               A
  5  3     A            2               B
  6  7     C            7               C
  </code></pre>