teshape | R Documentation |
Interconvert an array, a raw data frame, and frequency distribution data.frame.
teshape(data, out = c("freq", "tab", "raw"), var)
data |
a data frame or array. |
out |
the output format, see examples. |
var |
the name of the frequency variable in the dataset, if not
|
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.
a matrix containing the Markov basis as its columns (for easy addition to tables)
stats::xtabs()
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.