| fillForward {dembase} | R Documentation |
Fill in missing values in a vector by carrying forward observed values.
fillForward(x, firstBackward = TRUE)
x |
A vector. |
firstBackward |
Logical. Whether to fill upwards
if values at start of |
If one or more values at the start of the vector
are missing, and if firstBackward is TRUE,
then the missing values at the start are filled in
by carrying the first value backwards.
fillForward is based on Stack Overflow post
https://stackoverflow.com/questions/1782704
which in turn cites function na.locf
in package zoo.
A filled-in version of x.
x <- c("A", NA, NA, "B", NA)
fillForward(x)
## first values missing
x <- c(NA, NA, 1, NA, NA, 2, NA)
fillForward(x) # firstBackward TRUE by default
fillForward(x, firstBackward = FALSE)