blk.nearestMatch | R Documentation |
This function imputes the value of a quantity that would have been
observed at a given time using the value that was observed nearest
in time in a block-format
data set.
The imputation can be done forwards of backwards in time, and can be constrained such that the value is only imputed if the observation occurred within a certain time window.
blk.nearestMatch(time, id, observ.x, observ.t, id2 = id, direction = c("forward", "backward", "both"), tol = Inf, fill = NA, na.rm = FALSE, diff.op = difftime.default)
time |
A vector of times at which to impute values, in |
id,id2 |
A valid |
observ.x |
A vector of obseved values in |
observ.t |
A vector of observation times corresponding to |
direction |
Should value be carried forward in time, backward in time, or both? |
tol |
A numeric vector of length 1 or 2. The time window or tolerance for matching. See details. |
fill |
A value to use when no other value is appropriate. |
na.rm |
Should missing value in |
diff.op |
A function that subtracts one time from another. |
For a given list of times, finds the observed values that are closest in
time, searching either backward in time or forward in time. This is
done for each block of time
in a block-format
data set.
For a given time, a match is declared if an observation occurs
within a specific time window. The size of the time window is
specified with the tolerance parameter tol
. If tol
has length 2 then the first number is the tolerance for matching in
the “forward” direction and the second number is the tolerance for
matching in the “backward” direction; if tol
has length 1
then this is the tolerance for matching in both directions.
If two or more observations that are equidistant
from a time
value according to diff.op
, then one of
the values is selected arbitrarily. Forward matching value are
selected in preference to backward matching values (when
direction == "both"
).
A vector in block-format
with respect to id
containig the nearest match imputed values at times time
from
observ.x
.
Benjamin Rich <mail@benjaminrich.net>
block-format
blk.locf2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.