Learn R Programming

rbmi (version 1.6.1)

locf: Last Observation Carried Forward

Description

Returns a vector after applied last observation carried forward imputation.

Usage

locf(x)

Value

A vector of the same length as x in which each NA has been replaced by the most recent preceding non-NA value. Leading NAs (those with no earlier value to carry forward) are left unchanged.

Arguments

x

a vector.

Examples

Run this code
if (FALSE) {
locf(c(NA, 1, 2, 3, NA, 4)) # Returns c(NA, 1, 2, 3, 3, 4)
}

Run the code above in your browser using DataLab