I have the following data frame, and am trying to merge the two columns into one, while replacing NA\'s with the numeric values.
NA
ID A B 1
This question's been around for a while, but just to add another possible approach that does not depend on any libraries:
df$new = t(df[-1])[!is.na(t(df[-1]))] # ID A B new # 1 1 3 NA 3 # 2 2 NA 2 2 # 3 3 NA 4 4 # 4 4 1 NA 1