table.matrix: Cross-tabulate the rows or columns of a matrix.

View source: R/utils.R

table.matrixR Documentation

Cross-tabulate the rows or columns of a matrix.

Description

A version of the base table function designed for matrices. Taking a matrix as input, table.matrix returns a contingency table, index vector, and unique matrix.

Usage

table.matrix(data, MARGIN = 1)

Arguments

data

A matrix or data.frame, potentially containing non-unique patterns in its rows or columns.

MARGIN

A single integer specifying the array margin to be held fixed. (To get unique rows, select MARGIN = 1; for unique columns, select MARGIN = 2.)

Details

To apply this function to the columns of a matrix, simply transpose the matrix before executing the command, as in: table.matrix(t(data)).

Value

A list with the following elements:

  • table

    A contingency table of the counts of the number of occurrences of each unique row in the matrix.

  • index

    An index vector containing the indices (row numbers), in a matrix composed only of unique rows, to which each row in the original matrix maps.

  • unique.data

    A new matrix containing only the unique rows of the input matrix.

Author(s)

Caitlin Collins caitiecollins@gmail.com

Examples

## Not run: 
## load example data:
data("snps.ace")
x <- snps.ace

## basic use of fn on rows of x:
tab.out <- table.matrix(x)

## apply fn to columns of x:
tab.out <- table.matrix(t(x))

## End(Not run)


caitiecollins/treeWAS documentation built on Sept. 9, 2024, 8:23 a.m.