R Missing Value Replacement Function
问题 I have a table with missing values and I'm trying to write a function that will replace the missing values with a calculation based on the nearest two non-zero values. Example: X Tom 1 4.3 2 5.1 3 NA 4 NA 5 7.4 For X = 3 , Tom = 5.1 + (7.4-5.1)/2 . For X = 4 , Tom = (5.1 + (7.4-5.1)/2) + (7.4-5.1)/2 Does this function already exist? If not, any advice would be greatly appreciated. 回答1: A more usual way to do this (but not equivalent to the question) is to use linear interpolation: library(zoo