powered by
This function deletes those columns and/or rows in a matrix/data.frame that only contain 0s.
desparsify(X, dim = 2)
X with less rows or columns. (Class: the same than X).
Numeric matrix or data.frame of any size.
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).
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