title: Apply unique ID to events where i = j and j = i
body: <p>In the following table:</p>
  <pre><code>set.seed(5)
  df &lt;- data.frame(year=rep(c(2010:2011), each=8),
                   i=rep(c('66','66','6','6','65','65','6','6'), times=2),
                   j=rep(c('66','6','66','6','65','6','65','6'), times=2),
                   count=round(runif(8, 0, 5),0))
  </code></pre>
  <p>There are several events where <code>'i = j'</code> and <code>'i != j'</code>, I am trying to assign unique values to each of these events. In one scenario where <code>'i = j'</code> (i.e. <code>66 = 66</code> or <code>6 = 6</code>) I want to assign the value as '0'. However, if <code>'i != j'</code> I want to assign that event as <code>'1'</code> or higher depending on each unique group e.g., <code>'66_6'</code> or <code>'6_66'</code> is assigned a <code>'1'</code> and <code>'65_6'</code> or <code>'6_65'</code> is assigned a <code>'2'</code>.</p>
  <p>So far, I've only been able to figure out how to filter this table to include where these events, such as in the case of group 1 or 2, appear.</p>
  <pre><code>x &lt;- df[paste(df$i,df$j,sep = &quot;_&quot;) != paste(sapply(strsplit(paste(df$j,df$i,sep = &quot;_&quot;), &quot;\\s+&quot;), function(x) paste(rev(x), collapse=&quot; &quot;)),sep=&quot;&quot;),]
  </code></pre>
  <p>If anyone has any advice on how to proceed, I'd appreciate it.</p>