I have 2 columns in my dataframe such that for every row either of the following is true: 1. only one of them has a value (and the other is missing) 2. both have missing value
I need to create a new column which has missing value if both columns are missing or the non missing value if only 1 column has a value.
Example: A and B are columns in my dataset, C is the column I need to create:
A B C
1 NA 1
NA 6 6
NA NA NA
9 NA 9
4 NA 4
NA 3 3
Further, there are many such sets of columns that I wish to combine, so ideally I would like to do this with the help of a function where I can pass the names of new column, column1, column2 and the dataframe.
I am not able to understand how do I go about it. Can anyone please point me in the right direction.
(I searched for duplicate questions, but the ones I found were related to non missing values so I had to post this similar question)