I have a dataframe with columns that start with "dx". I want to create another column called primary
. If the value in all of the columns that start with "dx" is "I629"
or NA
, I want the value of primary
to be "Unspecified"
. Otherwise, I want the it to be the first non-"I629"
value.
My desired output:
dx1 dx2 dx3 dx4 dx5 primary
I629 NA NA NA NA Unspecified
S065 NA NA NA NA S065
I629 S066 NA NA NA S066
I629 I629 NA NA NA Unspecified