Computes the average missing value gap of a vector.

gapMiss(x, what = mean)

Arguments

x

a numeric vector

what

default is the arithmetic mean. One can include an own function that returns a vector of lenght 1 (e.g. median)

Value

The gap statistics

Details

The length of each sequence of missing values (gap) in a vector is calculated and the mean gap is reported

Author

Matthias Templ based on a suggestion and draft from Huang Tian Yuan.

Examples

v <- rnorm(20)
v[3] <- NA
v[6:9] <- NA
v[13:17] <- NA
v
#>  [1]  2.3307116  2.4220478         NA  0.9431652  0.5518939         NA
#>  [7]         NA         NA         NA -0.3524046 -0.9318654  0.4953990
#> [13]         NA         NA         NA         NA         NA  2.3456733
#> [19]  1.6845347  1.1032059
gapMiss(v)
#> [1] 3.333333
gapMiss(v, what = median)
#> [1] 4
gapMiss(v, what = function(x) mean(x, trim = 0.1))
#> [1] 3.333333
gapMiss(v, what = var)
#> [1] 4.333333