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
You can use unite from tidyr:
unite
tidyr
library(tidyr) df[is.na(df)] = '' unite(df, new, A:B, sep='') # ID new #1 1 3 #2 2 2 #3 3 4 #4 4 1