Learn R Programming

DescTools (version 0.99.6)

LOCF: Last Observation Carried Forward

Description

Replace NAs by the last observed value (aka "Last Observation Carried Forward").

Usage

LOCF(x)

Arguments

x
x is a vector containing NAs.

Value

  • a vector with the same dimension as x.

See Also

See also the package Hmisc for less coarse imputation functions.

Examples

Run this code
d.frm <- data.frame( 
  tag=rep(c("mo", "di", "mi", "do", "fr", "sa", "so"), 4)
, val=rep(c(runif(5), rep(NA,2)), 4) )

d.frm$locf <- LOCF( d.frm$val )
d.frm

Run the code above in your browser using DataLab