My data are as follows:
year site value dist
2019 A 200 10
2019 B NA 15
2019 C 50 30
2019 D NA 36
2020 A 300 10
2020 B NA 15
2020 C 100 30
2020 D NA 36
I would like to replace the NA values for site B as follows.
Site B NA = the sum of the products of the following two equations:
1) value of site A * (1/(dist of site B - dist of site A))
and
2) value of site C * (1/(dist of site C - dist of site B))
I would like to do this for each year, ideally using dplyr. Thank you in advance!