title: use ifelse to create new column in r
body: <p>My code is:</p>
  
  <pre><code>data$E&lt;-ifelse(data$D==data$B, "b", ifelse(data$D==data$C, "c", "unknowwn"))
  </code></pre>
  
  <p>result:   </p>
  
  <pre><code>  A   B   C   D   E
  1 16  16  NA  16  b
  2 20  NA  20  20  NA
  3 24  NA  NA  24  NA
  </code></pre>
  
  <p>But what I want is:</p>
  
  <pre><code>  A   B   C   D   E
  1 16  16  NA  16  b
  2 20  NA  20  20  c
  3 24  NA  NA  24  unknowwn
  </code></pre>
  
  <p>Dose anyone know how to solve this problem?
  Thanks!</p>