I would like to retain, for each group of a data frame, the first non-missing element until the last element (even if the last is missing). For example:
df <- structure(list(Ind = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), result = c(81,
90, NA, NA, 84, 86, 101, 134, NA, 78, NA, 103, NA, 112, NA, 111,
NA, 110, 256, 123, NA, NA, 194, 301, 98.5, 151, NA, 105, NA,
158, NA, 190, NA, 167, NA, 190, NA, NA, 113, 157, NA, 197, 155,
NA, 178, 146, NA, 153, 153, 147, NA, 170, NA, 157)), row.names = c(NA,
-54L), class = c("tbl_df", "tbl", "data.frame"))
In this example, group 3 should start from the 3rd observation and 1 and 2 should remain the same.