Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

xtabs

Cross tabulation


Description

xtabs creates a contingency table (optionally a sparse matrix) from cross-classifying factors, usually contained in a data-frame-like object, using a formula interface.

NOTE: This man page is for the xtabs S4 generic function defined in the BiocGenerics package. See ?stats::xtabs for the default method (defined in the stats package). Bioconductor packages can define specific methods for objects not supported by the default method.

Usage

xtabs(formula=~., data=parent.frame(), subset, sparse=FALSE, 
      na.action, addNA=FALSE, exclude=if(!addNA)c(NA, NaN),
      drop.unused.levels=FALSE)

Arguments

formula, subset, sparse, na.action, addNA, exclude, drop.unused.levels

See ?stats::xtabs for a description of these arguments.

data

A data-frame-like object.

Value

See ?stats::xtabs for the value returned by the default method.

Specific methods defined in Bioconductor packages should also return the type of object returned by the default method.

See Also

  • stats::xtabs for the default xtabs method.

  • showMethods for displaying a summary of the methods defined for a given generic function.

  • selectMethod for getting the definition of a specific method.

  • xtabs,DataFrame-method in the S4Vectors package for an example of a specific xtabs method (defined for DataFrame objects).

  • BiocGenerics for a summary of all the generics defined in the BiocGenerics package.

Examples

xtabs  # note the dispatch on the 'data' arg only
showMethods("xtabs")
selectMethod("xtabs", "ANY")  # the default method

library(S4Vectors)
showMethods("xtabs")
## The xtabs() method for DataFrame objects:
selectMethod("xtabs", "DataFrame")

BiocGenerics

S4 generic functions used in Bioconductor

v0.36.1
Artistic-2.0
Authors
The Bioconductor Dev Team
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.