sample_tibble <- tibble::tibble(
category = c("a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b"),
year = c(
"2015", "2016", "2017", "2018", "2019", "2020",
"2015", "2016", "2017", "2018", "2019", "2020"
),
value = c(NA, 3, NA, NA, 0, NA, 1, NA, NA, NA, 5, NA),
change_variable = c(1, 2, 3, 4, 1, 1, 0, 0, 0, 0, 0, 1)
)
sum_fill(
sample_tibble,
value,
change_variable,
start_with_zero = FALSE,
.by = c("category")
)
sum_fill(
sample_tibble,
value,
change_variable,
start_with_zero = TRUE,
.by = c("category")
)
Run the code above in your browser using DataLab