carryover: Carrying over values from previous elements

Description Usage Arguments Details Value See Also Examples

View source: R/carryover.R

Description

This function recursively carries over values from previous to subsequent elements of a vector

Usage

1
carryover(x, empty = NA)

Arguments

x

numeric or character, vector to be processed

empty

numeric or character scalar, value to be replaced

Details

The function recursively imputes to all values of x that are equal to empty the values of the preceding elements of x.

If the firs value of x is equal to empty, then an error is returned. For now you should take care of it by manually imputing the appropriate value.

Value

A vector x with all elements equal to empty replaced with last non-empty values.

See Also

approx for other ways of filling-in the gaps in vectors

Examples

1
2
3
4
x <- c(1, 2, 2, NA, NA, 1, 4)

# replacing NA's with last non-NA observation
carryover(x)

mbojan/mbtools documentation built on Nov. 9, 2017, 3:21 p.m.