I have a data-frame that looks as such:
ID col2 col3 col4
1 5 NA NA
2 NA NA 1
3 5 NA NA
4 19 NA 1
If col2 has a value, that cell should not change (even if columns 3 and 4 contains values). However, if col2 contains an "NA" value, I would like to return any non-NA's from col3 or col4, if they exist.
Desired output shown below, notice how row 2 has the "1" there now.
ID col2 col3 col4
1 5 NA NA
2 1 NA 1
3 5 NA NA
4 19 NA 1
I know this can be done manually by referencing each column using $ or [], but how can this be done using a for-loop or apply?
Thanks