Replace NA values if last and next non-NA value are the same
问题 I am trying to fill missing data based on whether the previous and last NA value are the same. For example, this is the dummy dataset: df <- data.frame(ID = c(rep(1, 6), rep(2, 6), rep(3, 6), rep(4, 6), rep(5, 6), rep(6, 6), rep(7, 6), rep(8, 6), rep(9, 6), rep(10, 6)), with_missing = c("a", "a", NA, NA, "a", "a", "a", "a", NA, "b", "b", "b", "a", NA, NA, NA, "c", "c", "b", NA, "a", "a", "a", "a", "a", NA, NA, NA, NA, "a", "a", "a", NA, "b", "a", "a", "a", "a", NA, NA, "a", "a", "a", "a", NA,