How can I recode the values NA of variable b
, with the values of the row in variable a
.
See df
with a
and b
: the expected output is df2
.
a<- c(10, 12, 8, 7, 6)
b<- c(5, NA, 6, NA, NA)
df <- data.frame (a,b)
df
df
# a b
# 1 10 5
# 2 12 NA
# 3 8 6
# 4 7 NA
# 5 6 NA
# df2
# a b
# 1 10 5
# 2 12 12
# 3 8 6
# 4 7 7
# 5 6 6