fill.na: Replace Missing Values in a Vector

Description Usage Arguments Details Value Author(s) Examples

Description

Missing values in a vector are replaced by the last (forward) or next (backward) observed value.

Usage

1
fill.na(vec, backwards = FALSE, na.rm = FALSE)

Arguments

vec

a vector

backwards

if FALSE NAs are replaced by the last observed value, if TRUE NAs are replaced by the next observed value

na.rm

if TRUE NAs at the start and end of vector are removed

Details

In the clinical literature, the procedure of replacing a missing value with the last observed value is known as the "Last Observation Carried Forward" imputation technique. However, there is a large body of literature suggesting that this method may lead to biased estimates of means and covariances and should therefore be avoided for imputation.

Value

A vector with replaced missing values.

Author(s)

Martin Hecht

Examples

1
2
3
(vec <- c(NA, 1, NA, NA, 2, NA, 3, NA))
fill.na(vec)
fill.na(vec, backwards = TRUE)

eatTools documentation built on May 2, 2019, 4:44 p.m.

Related to fill.na in eatTools...