nonzero: Methods for Function nonzero

Description Value Methods Note See Also Examples

Description

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

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)

Note

Originally we used the matrix.csr class from SparseM, but we have switched to the class dgCMatrix from package Matrix, as that package is part of the R distribution bundle now.

The idea is to have a function similar to which(x != 0, arr.ind=TRUE) if x is a matrix.

See Also

dgCMatrix-class

Examples

1
2
3
4
5
6
7
  (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 <- cbind(A.dgc, A.dgc)
  as.matrix(A2.dgc)
  nonzero(A2.dgc)

Example output

Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package:BiocGenericsThe following objects are masked frompackage:parallel:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked frompackage:stats:

    IQR, mad, sd, var, xtabs

The following objects are masked frompackage:base:

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: RColorBrewer
Loading required package: limma

Attaching package:limmaThe following object is masked frompackage:BiocGenerics:

    plotMA

Loading required package: Matrix
Loading required package: grid
Loading required package: lattice
     [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    1
[3,]    0    0    0
[4,]    0    0    0
[5,]    0    0  -34
Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  ..@ i       : int [1:2] 1 4
  ..@ p       : int [1:4] 0 0 0 2
  ..@ Dim     : int [1:2] 5 3
  ..@ Dimnames:List of 2
  .. ..$ : NULL
  .. ..$ : NULL
  ..@ x       : num [1:2] 1 -34
  ..@ factors : list()
     row col
[1,]   2   3
[2,]   5   3
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    0    0    0    0    0
[2,]    0    0    1    0    0    1
[3,]    0    0    0    0    0    0
[4,]    0    0    0    0    0    0
[5,]    0    0  -34    0    0  -34
     row col
[1,]   2   3
[2,]   5   3
[3,]   2   6
[4,]   5   6

Ringo documentation built on Nov. 8, 2020, 5:34 p.m.