fillForward {dembase}R Documentation

Use observed values to fill in missing values in vector

Description

Fill in missing values in a vector by carrying forward observed values.

Usage

fillForward(x, firstBackward = TRUE)

Arguments

x

A vector.

firstBackward

Logical. Whether to fill upwards if values at start of x are missing.

Details

If one or more values at the start of the vector are missing, and if firstBackward is TRUE, then the missing values at the start are filled in by carrying the first value backwards.

fillForward is based on Stack Overflow post https://stackoverflow.com/questions/1782704 which in turn cites function na.locf in package zoo.

Value

A filled-in version of x.

Examples

x <- c("A", NA, NA, "B", NA)
fillForward(x)

## first values missing
x <- c(NA, NA, 1, NA, NA, 2, NA)
fillForward(x) # firstBackward TRUE by default
fillForward(x, firstBackward = FALSE)

[Package dembase version 0.0.0.119 Index]