rowCounts {matrixStats}R Documentation

Counts the number of TRUE values in each row (column) of a matrix

Description

Counts the number of TRUE values in each row (column) of a matrix.

Usage

  rowCounts(x, na.rm=FALSE, ...)
  colCounts(x, na.rm=FALSE, ...)
  rowAlls(x, na.rm=FALSE, ...)
  colAlls(x, na.rm=FALSE, ...)
  rowAnys(x, na.rm=FALSE, ...)
  colAnys(x, na.rm=FALSE, ...)

Arguments

x A logical NxK matrix.
na.rm If TRUE, NAs are excluded first, otherwise not.
... Not used.

Value

rowCounts() (colCounts()) returns an integer vector of length N (K). The other methods returns a logical vector of length N (K).

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

Examples

x <- matrix(FALSE, nrow=10, ncol=5)
x[3:7,c(2,4)] <- TRUE
x[2:4,] <- TRUE
x[,1] <- TRUE
x[5,] <- FALSE
x[,5] <- FALSE

print(x)

print(rowCounts(x))       # 1 4 4 4 0 3 3 1 1 1
print(colCounts(x))       # 9 5 3 5 0

print(rowAnys(x))
print(which(rowAnys(x)))  # 1  2  3  4  6  7  8  9 10
print(colAnys(x))
print(which(colAnys(x)))  # 1 2 3 4

[Package matrixStats version 0.1.8 Index]