remove_sparse: Remove extremely sparse columns

Description Usage Arguments Details Value Examples

View source: R/remove-sparse.R

Description

remove_sparse() removes columns from sparse and dense matrices that have a sparsity value greater than a user-defined threshold.

Usage

1
2
3
4
5
6
7
remove_sparse(x, threshold)

## S3 method for class 'CsparseMatrix'
remove_sparse(x, threshold)

## S3 method for class 'matrix'
remove_sparse(x, threshold)

Arguments

x

A matrix or CsparseMatrix.

threshold

A double between 0 and 1 specifying the sparsity threshold at which to remove columns.

Details

remove_sparse() is an S3 generic with methods for:

Value

x with sparse columns removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Create a sparse matrix with very sparse columns
x <- Matrix::rsparsematrix(10, 5, 0.1)
colnames(x) <- paste0("x", 1:5)
# Print x
x

# Same matrix in dense format
xdense <- as.matrix(x)

# Drop duplicate columns
remove_sparse(x, threshold = 0.9)
remove_sparse(xdense, threshold = 0.9)

dmolitor/sparseprepr documentation built on Jan. 7, 2022, 9:58 p.m.