An option is to use tidyr::fill. The approach is to create columns as desired and TempDate in such a way that desired will have same value as variable but rows with "" (blank) value for variable will have desired as NA. Similarly TempDate will have same value as date but it will have NA for rows where variable got "" values.
fill both desired and TempDate and replace desired to NA where TempDate is older by more than 12 months than date.
library(tidyverse)
library(lubridate)
df %>% mutate(TempDate = as.Date(ifelse(variable=="", NA, date),origin = "1970-01-01"),
desired = ifelse(variable=="",NA, variable)) %>%
fill(desired, TempDate) %>%
mutate(desired = ifelse(date > (TempDate +months(12)), NA, desired)) %>%
select(-TempDate)
# date variable desired
# 1 2016-01-01 1 1
# 2 2016-02-01 2 2
# 3 2016-03-01 3 3
# 4 2016-04-01 3 3
# 5 2016-05-01 3 3
# 6 2016-06-01 33 33
# 7 2016-07-01 33
# 8 2016-08-01 33
# 9 2016-09-01 33
# 10 2016-10-01 33
# 11 2016-11-01 33
# 12 2016-12-01 33
# 13 2017-01-01 33
# 14 2017-02-01 33
# 15 2017-03-01 33
# 16 2017-04-01 33
# 17 2017-05-01 33
# 18 2017-06-01 33
# 19 2017-07-01 <NA>
# 20 2017-08-01 <NA>
# 21 2017-09-01 34 34
# 22 2017-10-01 34
Data: Based on image shared by OP
df <- data.frame(date = seq(as.Date("2016-01-01"), as.Date("2017-10-01"), by="month"),
variable = c(1,2,3,3,3,33,rep("",14),34,""), stringsAsFactors = FALSE)
df
# date variable
# 1 2016-01-01 1
# 2 2016-02-01 2
# 3 2016-03-01 3
# 4 2016-04-01 3
# 5 2016-05-01 3
# 6 2016-06-01 33
# 7 2016-07-01
# 8 2016-08-01
# 9 2016-09-01
# 10 2016-10-01
# 11 2016-11-01
# 12 2016-12-01
# 13 2017-01-01
# 14 2017-02-01
# 15 2017-03-01
# 16 2017-04-01
# 17 2017-05-01
# 18 2017-06-01
# 19 2017-07-01
# 20 2017-08-01
# 21 2017-09-01 34
# 22 2017-10-01