Learn R Programming

rmngb (version 0.6-1)

locf: Last Observation Carried Forward

Description

Returns the last non-missing observation in a vector.

Usage

locf(x)

Arguments

x
vector.

Value

Scalar corresponding to the last non-missing observation.

Examples

Run this code
tab <- data.frame(a1 = c(1, 4, 6),
                  a2 = c(3, NA, NA),
                  a3 = c(4, NA, 5))
apply(tab, 1, locf)

Run the code above in your browser using DataLab