sparsity | R Documentation |
Turning data frame with sparse columns into sparse matrix using
Matrix::sparseMatrix()
.
sparsity(x, sample = NULL)
x |
a data frame, matrix of sparse matrix. |
sample |
a integer or |
Only numeric 0s are considered zeroes in this calculations. Missing values,
logical vectors and then string "0"
aren't counted.
a single number, between 0 and 1.
# data frame
sparsity(mtcars)
# Matrix
set.seed(1234)
mat <- matrix(sample(0:1, 100, TRUE, c(0.9, 0.1)), nrow = 10)
colnames(mat) <- letters[1:10]
sparsity(mat)
# Sparse matrix
sparse_mat <- Matrix::Matrix(mat, sparse = TRUE)
sparsity(sparse_mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.