This question already has an answer here:
I've just started using R and i'm trying to replace the NULl values in each columns by the average of forward and backward values. Below is the sample dataframe that has couple of null values
A B C
1 1 2000
2 NA NA
3 4 5000
4 NA NA
5 7 8000
I'm trying to do something like this.
A B C
1 1 2000
2 2.5 3500
3 4 5000
4 5.5 6500
5 7 8000
tidyr seems to do half of the work df %>% fill("A",.direction = c("down"))
but how can i replace the average of the forward and the backward values ?