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.87231588  0.10668461          NA -0.32785359 -0.08536101          NA
#>  [7]          NA          NA          NA -0.55323819  1.40510888 -0.79546095
#> [13]          NA          NA          NA          NA          NA -0.07681765
#> [19]  0.89292492 -0.77750309
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