teshape: Interconvert data structures

View source: R/teshape.r

teshapeR Documentation

Interconvert data structures

Description

Interconvert an array, a raw data frame, and frequency distribution data.frame.

Usage

teshape(data, out = c("freq", "tab", "raw"), var)

Arguments

data

a data frame or array.

out

the output format, see examples.

var

the name of the frequency variable in the dataset, if not "freq".

Details

Multivariate categorical data can be represented in several ways. Three comon ways are : a contingency table, a data frame of raw observations (1 row = 1 subject), and a long data frame with a variable containing the counts in the contingency table.

Value

a matrix containing the Markov basis as its columns (for easy addition to tables)

See Also

stats::xtabs()

Examples


# converting a talbe to a data frame
(tab <- structure(
  array(1:8, c(2,2,2)),
  .Dimnames = list(
    A = c("a1", "a2"),
    B = c("b1", "b2"),
    C = c("c1", "c2")
  )
))

teshape(tab, "freq")
teshape(tab, "raw") # nrow = sum(1:8)


# converting a summarized data frame into a table or raw data frame
(data <- teshape(tab, "freq"))
teshape(data, "tab")
stats::xtabs(freq ~ ., data = data)
teshape(data, "tab") == stats::xtabs(freq ~ ., data = data)
teshape(data, "raw")


# converting a raw data frame into a table or summarized data frame
(data <- teshape(tab, "raw"))
teshape(data, "tab")
teshape(data, "freq")



dkahle/algstat documentation built on May 23, 2023, 12:29 a.m.