fill: Fill in Missing Values

Description Usage Arguments Details Value References Examples

View source: R/fill.R

Description

Fill in missing values in a vector, using the last recorded value.

Usage

1
fill(x, resetWhen = rep(FALSE, length(x)))

Arguments

x

A vector, can be character, numeric, or logical.

resetWhen

A logical vector, the same length as x, indicating elements that should not be filled in.

Details

Similar to na.locf in the zoo package, but works for "" in character vectors as well.

Value

A vector the same length as x, with all NAs or ""s replaced by the last value for the vector. Note that and missing values at the beginning of the vector will not be replaced.

References

This is a copy of the fill function from the [LW1949] package.

Examples

1
2
3
4
5
6
7
numvec <- c(NA, 1:5, NA, NA, NA, 10:12, NA)
newgroup <- c(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0)
fill(numvec)
fill(numvec, newgroup)

charvec <- c("", letters[1:5], "", "", "", letters[10:12], "")
fill(charvec)

JVAdams/jvamisc documentation built on Aug. 11, 2021, 6:43 a.m.