I have the following data frame,
df <- data.frame(id = c("a", "a", "a", "a", "b", "b", "b", "b"),
time = 1:4, value = c(100, NA, NA, 550, 300, NA, NA, 900))
Can someone suggest an approach for replacing the NA values in df by dividing the difference of the value column evenly over time? At time 1, A is 100 and at time 4 A is 550. How would one change the NAs in times 2 and 3 to 250 and 400? And then 500 and 700 for B at times 2 and 3?
I can write a complex for loop to brute force it, but is there a more efficient solution?