Replacing NAs in a column with the values of other column Replacing NAs in a column with the values of other column r r

Replacing NAs in a column with the values of other column


You can use coalesce:

library(dplyr)df1 <- data.frame(Letters, Char, stringsAsFactors = F)df1 %>%  mutate(Char1 = coalesce(Char, Letters))  Letters Char Char11       A    a     a2       B    b     b3       C <NA>     C4       D    d     d5       E <NA>     E