Learn R Programming

kerntools (version 1.2.0)

desparsify: This function deletes those columns and/or rows in a matrix/data.frame that only contain 0s.

Description

This function deletes those columns and/or rows in a matrix/data.frame that only contain 0s.

Usage

desparsify(X, dim = 2)

Value

X with less rows or columns. (Class: the same than X).

Arguments

X

Numeric matrix or data.frame of any size.

dim

A numeric vector. 1 indicates that the function should be applied to rows, 2 to columns, c(1, 2) indicates rows and columns. (Defaults: 2).

Examples

Run this code
dat <- matrix(rnorm(150),ncol=50,nrow=30)
dat[c(2,6,12),] <- 0
dat[,c(30,40,50)] <- 0
dim(desparsify(dat))
dim(desparsify(dat,dim=c(1,2)))

Run the code above in your browser using DataLab