title: Comparing two columns: logical- is value from column 1 also in column 2?
body: <p>I'm pretty confused on how to go about this.  Say I have two columns in a dataframe.  One column a numerical series in order (x), the other specifying some value from the first, or -1 (y).  These are results from a matching experiment, where the goal is to see if multiple photos are taken of the same individual.  In the example below, there 10 photos, but 6 are unique individuals.  In the y column, the corresponding x is reported if there is a match. y is -1 for no match (might as well be NAs).  If there is more than 2 photos per individual, the match # will be the most recent record (photo 1, 5 and 7 are the same individual below). The group is the time period the photo was take (no matches within a group!).  Hopefully I've got this example right:     </p>
  
  <pre><code>x &lt;- c(1,2,3,4,5,6,7,8,9,10)
  y &lt;- c(-1,-1,-1,-1,1,-1,1,-1,2,4)
  group &lt;- c(1,1,1,2,2,2,3,3,3,3)
  DF &lt;- data.frame(x,y,group)
  </code></pre>
  
  <p>I would like to create a new variable to name the unique individuals, and have a final dataset with a single row per individual (i.e. only have 6 rows instead of 10), that also includes the group information.  I.e. if an individual is in all three groups, there could be a value of "111" or if just in the first and last group it would be "101".  Any tips?</p>
  
  <p>Thanks for asking about the resulting dataset.  I realized my group explanation was bad based on the actual numbers I gave, so I changed the results slightly.  Bonus would also be nice to have, but not critical.</p>
  
  <pre><code>name &lt;- c(1,2,3,4,6,8)
  group_history &lt;- as.character(c('111','101','100','011','010','001'))
  bonus &lt;- as.character(c('1,5,7','2,9','3','4,10','6','8')) 
  results_I_want &lt;- data.frame(name,group_history,bonus)
  </code></pre>
  
  <p>My word, more mistakes fixed above...</p>