na_locf: Last observation carry forward

Description Usage Arguments Value See Also Examples

Description

Fill missing values in a time series (or in a column of a longitudional data set) with the last observation carry forward method.

Usage

1

Arguments

dataset

A data frame, tibble or dataset object created by dataset, with time, geo, value, frequency, obs_status and method columns.

...

Pass on arguments of na.locf. The zoo defaults settings are changed to maxgap=1.

Value

A tibble updated with the forward carried values.

See Also

Other approximation functions: na_approx(), na_nocb()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
example_df <- data.frame (
   time = rep(as.Date (paste0(2018:2021, "-01-01")),3),
   geo = c( rep("NL", 4), rep("BE", 4), rep("LU", 4)),
   value = c(10,11, NA_real_, 12, NA_real_, 21,22,23, 5,6,7,NA_real_),
   freq = rep("A", 12)
)
example_df$method <- ifelse(is.na(example_df$value), "missing", "actual")
example_df$obs_status <- example_df$method

na_locf ( example_df )
}

dataobservatory-eu/dataobservatory documentation built on Jan. 7, 2022, 8:55 p.m.