I've a data frame with missing values is some column (who doesn't). For example:
df <- data.frame(x = c(2,NA,4), y = 5:7)
df
x y
1 2 5
2 NA 6
3 4 7
I would like to replace the missing value with a value of a different column. Obviously there are a lot of ways to do so, for example:
df %>%
mutate(x = ifelse(is.na(x), y, x))
x y
1 2 5
2 6 6
3 4 7
However, I am looking for something more elegant, like
df %>% fill(x,y)
but couldn't find anything. Does something like this exist?
Thanks!