as.matrix: Convert xtabs To matrix

Description Usage Arguments Details Author(s) See Also Examples

Description

This function converts an xtabs object to a matrix.

Usage

1
2
## S3 method for class 'xtabs'
as.matrix(x, ...)

Arguments

x

an object of class xtabs

...

additional arguments to be passed to or from methods.

Details

An xtabs object is indeed already a matrix, but won't be converted to a pure matrix by as.matrix.default function, as its class definition will remain unchanged. Some functions expecting a pure matrix may fail, when fed with a xtabs object. as.matrix.xtabs will drop the classes and the call attribute.
Note that unclass would as well discard the classes xtabs and table, but retain the "call" attribute.

Author(s)

Andri Signorell <andri@signorell.net>

See Also

as.matrix, xtabs, unclass

Examples

1
2
3
4
5
6
7
tab <- xtabs( ~ driver + operator, data=d.pizza)

str(tab)
class(tab)

str(as.matrix(tab))
class(as.matrix(tab))

AndriSignorell/DescTools documentation built on April 8, 2021, 5:51 a.m.