Learn R Programming

arkhe (version 1.10.0)

sparsity: Sparsity

Description

Computes data sparsity (proportion of zeros).

Usage

sparsity(x, ...)

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

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

Value

A length-one numeric vector.

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?

Author

N. Frerebeau

Details

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

See Also

Other data summaries: describe()

Examples

Run this code
## 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)

Run the code above in your browser using DataLab