| proxy_fill | R Documentation |
Fills gaps in a variable based on changes in a proxy variable, using ratios between the filled variable and the proxy variable, and labels output accordingly.
proxy_fill(df, var, proxy_var, time_index, ...)
df |
A tibble data frame containing one observation per row. |
var |
The variable of df containing gaps to be filled. |
proxy_var |
The variable to be used as proxy. |
time_index |
The time index variable (usually year). |
... |
Optionally, additional arguments that will be passed to
|
A tibble dataframe (ungrouped) where gaps in var have been filled, a new proxy_ratio variable has been created, and a new "source" variable has been created indicating if the value is original or, in case it has been estimated, the gapfilling method that has been used.
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),
proxy_variable = c(1, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6)
)
proxy_fill(sample_tibble, value, proxy_variable, year, .by = c("category"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.