title: Decide if variables are equal by rank and id
body: <pre><code>DF&lt;-data.frame(id=c(1,1,1,2,2,2),rank=c(&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;1&quot;,&quot;2&quot;,&quot;3&quot;),code=c(&quot;A&quot;,&quot;B&quot;,&quot;B&quot;,&quot;B&quot;,&quot;B&quot;,&quot;A&quot;))
  
  DF
    id rank code
  1  A1    1    A
  2  A1    2    B
  3  A1    3    B
  4  B2    1    B
  5  B2    2    B
  6  B2    3    A
  </code></pre>
  <p>Desired output:</p>
  <pre><code>  id rank code type1 type2 type3
  1  A1    1    A    aa   MIX   MIX
  2  A1    2    B    NA   MIX   MIX
  3  A1    3    B    NA    NA   MIX
  4  B2    1    B    bb    bb   MIX
  5  B2    2    B    NA    bb   MIX
  6  B2    3    A    NA    NA   MIX
  </code></pre>
  <p>All is grouped by <code>id</code></p>
  <p><code>type1</code> gets <code>code</code> where <code>rank</code> = 1.</p>
  <p><code>type2</code> gets <code>code</code> where <code>rank</code> = 1-2. If <code>code</code> is different in <code>rank</code> 1 and 2, then <code>MIX</code></p>
  <p><code>type3</code> gets <code>code</code> where <code>rank</code> = 1-3. etc. etc.</p>
  <p>Anyone? :)</p>