R: Interpolation of NAs by group
I would like to perform a linear interpolation in a variable of a data frame which takes into account the: 1) time difference between the two points, 2) the moment when the data was taken and 3) the individual taken for measure the variable. For example in the next dataframe: df <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1,1,1,1,1,2,2,2), Value=c(1, 2, 3, NA, 5, NA, 7, 5, NA, 7)) df I would like to obtain: result <- data.frame(time=c(1,2,3,4,5,6,7,1,2,3), Individuals=c(1,1,1,1,1,1,1,2,2,2), Value=c(1, 2, 3, 4, 5, 6, 7, 5, 5.5, 6)) result I cannot use exclusively the function