| gap_id | R Documentation |
These functions are able to identify gaps in vectors (contiguous NA values)
and fill them with custom values.
The function gap_id() identify contiguous NA values and assign to them
an integer as identifier. The 0 is indicated for values outside of the gaps.
For the function gap_fill() only the linear method is yet implemented
(linear interpolation between the values neighbouring the gap). The argument
gap in this function can be the output of gap_id().
gap_id(x)
gap_fill(x, gap, method = "linear")
x |
A vector where gaps have to be detected. |
gap |
An integer vector with the identity of gaps (see details). |
method |
Method used to fill gaps. |
An integer vector with the IDs of gaps for gap_id(), while
gap_fill() is the vector x with NAs replaced by custom values.
Miguel Alvarez (malvarez@uni-bonn.de).
## A vector with two gaps
A <- c(1:5, NA, NA, 7:10, NA, NA, NA, 16:20)
A
## Identification of gaps
B <- gap_id(A)
B
## Linear interpolation in gaps
A_filled <- gap_fill(A, B)
par(mfrow = c(2, 1))
plot(1:length(A), A, type = "l")
plot(1:length(A_filled), A_filled, type = "l")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.