fill {LW1949} | R Documentation |
Fill in Missing Values
Description
Fill in missing values in a vector, using the last recorded value.
Usage
fill(x, resetWhen = rep(FALSE, length(x)))
Arguments
x |
A vector, can be character, numeric, or logical. |
resetWhen |
A logical vector, the same length as |
Details
Similar to na.locf
in the zoo
package,
but works for "" in character vectors as well.
Value
A vector the same length as x
, with all NAs or ""s replaced by
the last value for the vector.
Note that and missing values at the beginning of the vector will not
be replaced.
Examples
numvec <- c(NA, 1:5, NA, NA, NA, 10:12, NA)
newgroup <- c(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0)
fill(numvec)
fill(numvec, newgroup)
charvec <- c("", letters[1:5], "", "", "", letters[10:12], "")
fill(charvec)
[Package LW1949 version 1.1.0 Index]