I have a data frame with 3 different identifications and sometimes they overlap. I want to create a new column, with only one of those ids, in an order of preference (id1>id2>id3). Ex.:
id1 id2 id3
12 145 8763
45 836 5766
13 768 9374
836 5766
12 145
9282
567
45 836 5766
and I want to have:
id1 id2 id3 id.new
12 145 8763 12
45 836 5766 45
13 768 9374 13
836 5766 836
9282 9282
567 567
I have tried the if else,which, grep functions.. but I can't make it work.
Ex. of my try:
df$id1 <- ifelse(df$id1 == "", paste(df$2), (ifelse(df$id1)))
I am able to do this on Excel, but I am switching to R, for being more reliable and reproducible :) But in excel I would use:
=if(A1="",B1,(if(B1="",C1,B1)),A1)