ctable | R Documentation |
ctable
yields a contingency table (as a table
)
in analogy to creating an array by array
.
ctable(
data,
dim = length(data),
dimnames = NULL,
by_row = FALSE,
as_df = FALSE,
quiet = FALSE
)
data |
The data to be used (required;
frequency counts, as a |
dim |
The dimensions to be used
(as a numeric |
dimnames |
The dimension names to be used
(as a |
by_row |
(Boolean):
Are |
as_df |
(Boolean):
Return result as a |
quiet |
Boolean: Hide feedback messages?
Default: |
ctable
internally passes its arguments to array
before coercing the resulting array
into a table
or data.frame
.
The order of elements in its arguments data
, dim
,
and dimnames
must correspond to the defaults of array
.
For instance, data
are entered in a by-column fashion
and the dimensions in dimnames
from left/y, top/x, to group/table/z, etc.
A table.
subtable
for extracting a subset of a table;
sublist
for extracting subsets of a list;
table
and array
for the underlying data structures.
Other array functions:
add_dimnames()
,
expand_freq_table()
,
flatten_array()
,
subtable()
# Prepare dimnames (as lists):
l_24 <- list(rows = c("A", "B"), cols = letters[1:4])
l432 <- list(Ys = letters[1:4], Xs = LETTERS[1:3], group = c("I", "II"))
# Standard use:
ctable(1:8, dim = c(2,4 ), dimnames = l_24)
ctable(1:24, dim = c(4, 3, 2), dimnames = l432)
# by row:
ctable(1:8, dim = c(2, 4), dimnames = l_24, by_row = TRUE)
ctable(1:24, dim = c(4, 3, 2), dimnames = l432, by_row = TRUE)
# Return as df:
ctable(1:8, dim = c(2, 4), dimnames = l_24, as_df = TRUE)
ctable(1:24, dim = c(4, 3, 2), dimnames = l432, as_df = TRUE)
# No dimnames:
ctable(1:8, dim = c(2, 4))
ctable(1:8, dim = c(2, 2, 2))
# Non-integers:
ctable(1:9/3, dim = c(3, 3), quiet = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.