remove_empty: Remove empty (all-zero) columns

Description Usage Arguments Details Value Examples

View source: R/remove-empty.R

Description

remove_empty() removes all-zero columns from sparse and dense matrices.

Usage

1
2
3
4
5
6
7
remove_empty(x)

## S3 method for class 'CsparseMatrix'
remove_empty(x)

## S3 method for class 'matrix'
remove_empty(x)

Arguments

x

A matrix or CsparseMatrix.

Details

remove_empty() is an S3 generic with methods for:

Value

x with all-zero columns removed.

Examples

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

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

# Drop empty columns
remove_empty(x)
remove_empty(xdense)

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