Column1 Column2 Column3
3 3 1
2 3 2
1 NA 2
NA 4 1
2 NA NA
NA NA NA
I want to create a new column (Column 4) with the following conditions:
- If columns 1 and 2 have the same value, the value in column 4 is the same as columns 1 and 2.
- If columns 1 and 2 have different values, the value in column 4 should be 5.
- If column 1 or column 2 have an NA, pick the value from column 3.
- 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.
- If all the columns have NA, then column 4 should have NA too.
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)
Thanks in advance for answering this query.

