Learn R Programming

runner (version 0.2.1)

fill_run: 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 of any type where NA are replaced

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 befault run_for_first = TRUE

only_within

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

Value

numeric vector of length equals length of x containing all x elements with NA replaced with previous non-NA element.

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab