title: Applying multiple if-else conditions on different columns in R
body: <p><a href="https://i.stack.imgur.com/4JbMp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4JbMp.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/WYWVQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WYWVQ.png" alt="enter image description here" /></a>I have the following dataset:</p>
  <pre><code>Column1   Column2   Column3
        3         3         1        
        2         3         2        
        1        NA         2        
       NA         4         1        
        2        NA        NA        
       NA        NA        NA       
  </code></pre>
  <p>I want to create a new column (Column 4) with the following conditions:</p>
  <ol>
  <li>If columns 1 and 2 have the same value, the value in column 4 is the same as columns 1 and 2.</li>
  <li>If columns 1 and 2 have different values, the value in column 4 should be 5.</li>
  <li>If column 1 or column 2 have an NA, pick the value from column 3.</li>
  <li>If 2 columns out of 3 have NA, then the value in column 4 should be that of the column that has a non-NA value.</li>
  <li>If all the columns have NA, then column 4 should have NA too.</li>
  </ol>
  <pre>
  Column1   Column2   Column3   Column4
        3         3         1         3 (Condition 1) 
        2         3         2         5 (Condition 2)
        1        NA         2         2 (Condition 3)
       NA         4         1         1 (Condition 3)
        2        NA        NA         2 (Condition 4)
       NA        NA        NA        NA (Condition 5)
  </pre>
  <p>Thanks in advance for answering this query.</p>