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
Another very simple solution in this case is to use the rowSums function.
rowSums
df$New<-rowSums(df[, c("A", "B")], na.rm=T) df<-df[, c("ID", "New")]
Update: Thanks @Artem Klevtsov for mentioning that this method only works with numeric data.