Learn R Programming

Ringo (version 1.36.0)

nonzero-methods: Methods for Function nonzero

Description

Auxiliary functions to retrieve the indices of non-zero elements in sparse matrices.

Arguments

Value

A two-column matrix. Each row gives the row and column index of a non-zero element in the supplied matrix x.

Methods

x = "dgCMatrix"
returns the indices of non-zero elements in matrices of class dgCMatrix
x = "matrix.csr"
returns the indices of non-zero elements in matrices of class matrix.csr
x = "matrix"
returns the indices of non-zero elements in matrices of base class matrix; equivalent to which(x != 0, arr.ind=TRUE)

See Also

dgCMatrix-class

Examples

Run this code
  (A <- matrix(c(0,0,0,0,0,1,0,0,0,0,0,0,0,0,-34),
               nrow=5, byrow=TRUE))
  str(A.dgc <- as(A, "dgCMatrix"))
  nonzero(A.dgc)
  A2.dgc <- Matrix::cBind(A.dgc, A.dgc)
  as.matrix(A2.dgc)
  nonzero(A2.dgc)

Run the code above in your browser using DataLab