table.to.vectors: Recover Raw Data Vectors from Contingency Table

View source: R/table.to.vectors.R

table.to.vectorsR Documentation

Recover Raw Data Vectors from Contingency Table

Description

Converts a contingency table (count data) back into two vectors of raw observations. This is useful when you have a summary table but need to run tests that require raw data vectors (like the functions in this package).

Usage

table.to.vectors(x)

Arguments

x

A numeric matrix or contingency table containing non-negative integer counts. Must not contain NA values.

Value

A list containing two integer vectors:

x_vector

A vector of row indices corresponding to the observations.

y_vector

A vector of column indices corresponding to the observations.

Examples

library("Upsilon")

# Create a sample contingency table
# Rows = Variable A (levels 1,2), Cols = Variable B (levels 1,2,3)
tab <- matrix(c(10, 5, 2, 8, 5, 10), nrow = 2, byrow = TRUE)
print(tab)

# Recover the raw vectors
res <- table.to.vectors(tab)

# Check the result
length(res$x_vector) # Should be sum(tab) = 40
head(cbind(res$x_vector, res$y_vector))
table(res$x_vector, res$y_vector) # Should as same as tab

Upsilon documentation built on March 7, 2026, 5:07 p.m.