carryover | R Documentation |
This function recursively carries over values from previous to subsequent elements of a vector
carryover(x, empty = NA)
x |
numeric or character, vector to be processed |
empty |
numeric or character scalar, value to be replaced |
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.
A vector x
with all elements equal to empty
replaced
with last non-empty
values.
approx
for other ways of filling-in the gaps in
vectors
x <- c(1, 2, 2, NA, NA, 1, 4)
# replacing NA's with last non-NA observation
carryover(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.