gap_id: Identifying and filling gaps

View source: R/gap_id.R

gap_idR Documentation

Identifying and filling gaps

Description

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().

Usage

gap_id(x)

gap_fill(x, gap, method = "linear")

Arguments

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.

Value

An integer vector with the IDs of gaps for gap_id(), while gap_fill() is the vector x with NAs replaced by custom values.

Author(s)

Miguel Alvarez (malvarez@uni-bonn.de).

Examples

## 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")


kamapu/Lexiguel documentation built on July 29, 2022, 7:52 p.m.