Question:
V is a vector with multiple NAs. Write a function to replace these NA values such that a missing value at index i should be replaced by the mean of the non-NA values at index p and q where |p – i| + |q – i| is minimized.
So, if my vector is ("NA", 1, 2, "NA", "NA", 3)
then my result needs to be (1.5, 1, 2, 1.5, 1.5, 3)
How can I write a nested for loop to produce this output?