fill_run: Fill NA with previous non-NA element

View source: R/RcppExports.R

fill_runR Documentation

Fill NA with previous non-NA element

Description

Fill NA with last non-NA element.

Usage

fill_run(x, run_for_first = FALSE, only_within = FALSE)

Arguments

x

(vector, data.frame, matrix, xts, grouped_df)
Input in runner custom function f.

run_for_first

If first elements are filled with NA, run_for_first = TRUE allows to fill all initial NA with nearest non-NA value. By default run_for_first = TRUE

only_within

NA are replaced only if previous and next non-NA values are the same. By default only_within = TRUE

Value

vector - x containing all x elements with NA replaced with previous non-NA element.

Examples

fill_run(c(NA, NA, 1:10, NA, NA), run_for_first = TRUE)
fill_run(c(NA, NA, 1:10, NA, NA), run_for_first = TRUE)
fill_run(c(NA, NA, 1:10, NA, NA), run_for_first = FALSE)
fill_run(c(NA, NA, 1, 2, NA, NA, 2, 2, NA, NA, 1, NA, NA), run_for_first = TRUE, only_within = TRUE)

runner documentation built on May 29, 2024, 10:22 a.m.