powered by
Convert a data frame or a matrix into an xtabs object.
xtabs
as.xtabs(x, ...)# S3 method for data.frame as.xtabs(x, rowvar = NULL, colvar = NULL, labels = 1, ...)# S3 method for matrix as.xtabs(x, rowvar = NULL, colvar = NULL, ...)
# S3 method for data.frame as.xtabs(x, rowvar = NULL, colvar = NULL, labels = 1, ...)
# S3 method for matrix as.xtabs(x, rowvar = NULL, colvar = NULL, ...)
An xtabs object.
object (typically a data frame) to be converted to xtabs format
additional arguments to be passed to or from methods.
name of the row variable as character string
name of the column variable as character string
column of data frame that contains the labels of the row variable.
The intended use is to convert a two-way contingency table stored in a data frame or a matrix into an xtabs object.
# example from example(fisher.test) df <- data.frame( X=c('Tea','Milk'), Tea=c(3,1), Milk=c(1,3) ) xt <- as.xtabs(df, rowvar="Guess", colvar="Truth"); xt if (require(vcd)) { mosaic(xt) }
Run the code above in your browser using DataLab