Processing math: 100%
Skip to contents

This function computes the ratio of missing elements.

See the Details section below for further information.

Usage

rowMissingValueRatio(x, g = NULL)

Arguments

x

matrix or data.frame, where rows are features and columns are observations.

g

(optional) vector or factor object giving the group for the corresponding elements of x.

Value

A vector of length nrow(x) containing the computed ratios. If g is provided, a matrix with ratios for each class as column vectors is returned.

Details

If g = NULL, for each feature a missing value ratio (MVR) is computed as:

MissingValueRatio(MVR)=NumberofmissingvaluesTotalnumberofobservations

If g is provided, the missing value ratios MVRij are computed for each group j as:

MVRij=NumberofmissingvaluesinjthclassNumberofobservationsinjthclass

Author

Alessandro Barberis

Examples

#Seed
set.seed(1010)

#Define row/col size
nr = 5
nc = 10

#Data
x = matrix(
 data = sample(x = c(1,2), size = nr*nc, replace = TRUE),
 nrow = nr,
 ncol = nc,
 dimnames = list(
   paste0("f",seq(nr)),
   paste0("S",seq(nc))
 )
)

#Grouping variable
g = c(rep("a", nc/2), rep("b", nc/2))

#Force 1st feature to have 40% of missing values
x[1,seq(nc*0.4)] = NA

#Compute MVR
rowMissingValueRatio(x = x)
#>  f1  f2  f3  f4  f5 
#> 0.4 0.0 0.0 0.0 0.0 

#Compute MVR by class
rowMissingValueRatio(x = x, g = g)
#>      a b
#> f1 0.8 0
#> f2 0.0 0
#> f3 0.0 0
#> f4 0.0 0
#> f5 0.0 0