Learn R Programming

timefully (version 0.1.0)

fill_from_past: Fill from past values

Description

If back index ( NA index - back) is lower than zero then the it is filled with the first value of the data frame. If the value in the back index is also NA, it iterates backwards until finding a non-NA value.

Usage

fill_from_past(dtf, varnames, back = 24)

Value

tibble or data.frame

Arguments

dtf

data.frame or tibble, first column of name datetime being of class datetime and rest of columns being numeric

varnames

character or vector of characters, column names with NA values

back

integer, number of indices (rows) to go back and get the filling value

Examples

Run this code
past_data <- data.frame(
  datetime = as.POSIXct("2024-01-01 00:00:00", tz = "UTC") + 0:3 * 3600,
  consumption = c(1.2, NA, NA, 2.5)
)
fill_from_past(past_data, "consumption", back = 1)

Run the code above in your browser using DataLab