fill: Fill in Missing Values

Description Usage Arguments Details Value Examples

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.

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)

LW1949 documentation built on May 2, 2019, 6:11 a.m.