Learn R Programming

whep (version 0.2.0)

proxy_fill: Fill gaps using a proxy variable

Description

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.

Usage

proxy_fill(df, var, proxy_var, time_index, ...)

Value

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.

Arguments

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 linear_fill() with the ratios. See that function to know the accepted arguments.

Examples

Run this code
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"))

Run the code above in your browser using DataLab