expandTable: Converts results in a contingency table into the original raw...

Description Usage Arguments Value Note See Also Examples

View source: R/misc-utils.R

Description

Converts results in a contingency table into the original raw data.

Usage

1
expandTable(x, var.names = NULL, ...)

Arguments

x

A matrix containing the contingency table.

var.names

A vector of strings used to name the variables in the new data frame.

...

Additional arguments for the type.convert function.

Value

Returns a data frame of the expanded raw data from the contingency table.

Note

This function is largely an implementation of the commands detailed in Mark Schwartz's R-help e-mail of 17Oct06 and 5Oct07.

See Also

as.data.frame.table, type.convert, and expandTable in epitools.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Simple example
d <- matrix(c(3,2,1,1,2,3,3,2,1),nrow=3,byrow=TRUE)
colnames(d) <- c(2,4,6)
rownames(d) <- c(1,2,3)
d
rawd <- expandTable(d,c("RowVar","ColVar"))
rawd
with(rawd,table(RowVar,ColVar))

## Example with zeroes, that is not square, and factor label names
f <- matrix(c(0,2,1,1,0,3,1,2,0,0),nrow=2,byrow=TRUE)
colnames(f) <- c("c1","c2","c3","c4","c5")
rownames(f) <- c("r1","r2")
f
rawf <- expandTable(f,c("RowVar","ColVar"))
rawf
with(rawf,table(RowVar,ColVar))

droglenc/NCStats documentation built on June 5, 2021, 2:06 p.m.