sparsity {arkhe}R Documentation

Sparsity

Description

Computes data sparsity (proportion of zeros).

Usage

sparsity(x, ...)

## S4 method for signature 'matrix'
sparsity(x, count = FALSE)

## S4 method for signature 'data.frame'
sparsity(x, count = FALSE)

Arguments

x

An R object (should be a matrix or a data.frame).

...

Currently not used.

count

A logical scalar: should a count be returned instead of a proportion?

Details

If x is a data.frame, sparsity is computed on numeric variables only.

Value

A length-one numeric vector.

Author(s)

N. Frerebeau

See Also

Other data summaries: describe()

Examples

## Create a data matrix
X <- matrix(sample(0:9, 15, TRUE), nrow = 3, ncol = 5)

## Add NA
k <- sample(1:15, 3, FALSE)
X[k] <- NA

## Sparsity
sparsity(X)

## Quick description
describe(X)

[Package arkhe version 1.6.0 Index]