I have a dataframe with some NA values:
dfa <- data.frame(a=c(1,NA,3,4,5,NA),b=c(1,5,NA,NA,8,9),c=c(7,NA,NA,NA,2,NA)) dfa
I would like t
We can use Map from base R to do a columnwise comparison between the two datasets
Map
base R
dfa[] <- Map(function(x,y) {x[is.na(x)] <- y[is.na(x)]; x}, dfa, dfrepair) dfa # a b c #1 1 1 7 #2 3 5 7 #3 3 4 6 #4 4 3 5 #5 5 8 2 #6 7 9 3