my df looks like this
df <- read.table(text="
id date
2 NA
2 2018-11-01
2 NA
2 NA
2 2019-11-01
2 NA
3 2018-01-01
3 NA
3 NA
3 NA
", header=TRUE)
My goal is to fill NAs by value above. But once is value not NA, then I'd like to fill next NAs with that. In other words, result should look like this:
result <- read.table(text="
id date
2 NA
2 2018-11-01
2 2018-11-01
2 2018-11-01
2 2019-11-01
2 2019-11-01
3 2018-01-01
3 2018-01-01
3 2018-01-01
3 2018-01-01
", header=TRUE)
Note that first row for id 2 is NA and since there is no row above it, value is still NA,