Description Usage Arguments Details Value Examples
View source: R/miscellaneous-functions.R
Fill in missing values in a vector by carrying forward observed values.
1 | 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
.
1 2 3 4 5 6 7 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.