Combine column to remove NA's yet prioritize specific replacements
I'm learning to update column data using this previous post . However, is there a trick for specifying which column should provide the final updated value in case of a conflict. For example, I can combine columns of data as long as only one value exists per row: data <- data.frame('a' = c('A','B','C','D','E'), 'x' = c(NA,NA,3,NA,NA), 'y' = c(1,2,NA,NA,NA), 'z' = c(NA,NA,NA,4,5)) cbind.data.frame(data3[1], mycol=c(na.omit(c(t(data3[, -1]))))) How would I force the value to come from newVal in the following case? data <- data.frame('a' = c('A','B','C','D','E','F'), 'x' = c(NA,NA,NA,3,NA,NA), 'y'