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]  0.5777091  0.1181949         NA  0.8620865 -0.2432367         NA
#>  [7]         NA         NA         NA -2.2741149  2.6825572 -0.3612213
#> [13]         NA         NA         NA         NA         NA -1.1775633
#> [19] -0.9758506  1.0650573
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