I wonder how to replace NAs in a column with the values of other column in R using dplyr. MWE is below.
NA
R
dplyr
Letters <- LETT
You can use coalesce:
coalesce
library(dplyr) df1 <- data.frame(Letters, Char, stringsAsFactors = F) df1 %>% mutate(Char1 = coalesce(Char, Letters)) Letters Char Char1 1 A a a 2 B b b 3 C <NA> C 4 D d d 5 E <NA> E