untable: Contingency Table

View source: R/untable.R

untableR Documentation

Contingency Table

Description

Constructs a data frame from the count data in a contingency table, using the column and row names as classes.

Usage

untable(x, rows = "Rows", cols = "Columns", counts = FALSE)

Arguments

x

a contingency table. Missing values are not permitted.

rows

a character string indicating the name of the column containing the data for the rows. The default column name is "Rows."

cols

a character string indicating the name of the column containing the data for the columns. The default column name is "Columns."

counts

a logical value indicating whether there should be one row in the result for each observation, which is the default counts = FALSE, or whether there should be a column that contains the number of counts for each row and column class, counts = TRUE.

Value

A data frame containing two columns named from rows and cols and an optional column named "Counts" if counts is set to TRUE.

Note

The output for this function can be used for input to contingency table analysis functions that require a data frame rather than a contingency table. To convert a column from factor to ordered, use the ordered function.

See Also

ordered

Examples


## Create a small synthetic data matrix
mdat <- matrix(seq(6), nrow = 2, ncol=3,
   dimnames = list(c("row1", "row2"), c("C.1", "C.2", "C.3")))
untable(mdat)

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.