carryover: Carrying over values from previous elements

carryoverR Documentation

Carrying over values from previous elements

Description

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

Usage

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


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

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


mbojan/mbtools documentation built on Oct. 16, 2023, 8:18 p.m.