colTabulates-xgCMatrix-method: Tabulates the values in a matrix-like object by row (column)

colTabulates,xgCMatrix-methodR Documentation

Tabulates the values in a matrix-like object by row (column)

Description

Tabulates the values in a matrix-like object by row (column).

Usage

## S4 method for signature 'xgCMatrix'
colTabulates(x, rows = NULL, cols = NULL, values = NULL, useNames = TRUE)

## S4 method for signature 'xgCMatrix'
rowTabulates(x, rows = NULL, cols = NULL, values = NULL, useNames = TRUE)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

values

the values to search for.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

The S4 methods for x of type matrix, array, table, or numeric call matrixStats::rowTabulates / matrixStats::colTabulates.

Value

a numeric NxJ (KxJ) matrix, where N (K) is the number of rows (columns) for which the J values are calculated.

See Also

  • matrixStats::rowTabulates() and matrixStats::colTabulates() which are used when the input is a matrix or numeric vector.

  • base::table()

Examples

mat <- matrix(rpois(15, lambda = 3), nrow = 5, ncol = 3)
  mat[2, 1] <- NA_integer_
  mat[3, 3] <- 0L
  mat[4, 1] <- 0L

  print(mat)

  rowTabulates(mat)
  colTabulates(mat)

  rowTabulates(mat, values = 0)
  colTabulates(mat, values = 0)

const-ae/sparseMatrixStats documentation built on April 10, 2024, 5:27 p.m.