matrix_to_long {segregation} | R Documentation |
Turns a contingency table into long format
Description
Returns a data.table in long form, such that it is suitable for use in mutual_total, etc. Colnames and rownames of the matrix will be respected.
Usage
matrix_to_long(
matrix,
group = "group",
unit = "unit",
weight = "n",
drop_zero = TRUE
)
Arguments
matrix |
A matrix, where the rows represent the units, and the column represent the groups. |
group |
Variable name for group. (Default |
unit |
Variable name for unit. (Default |
weight |
Variable name for frequency weight. (Default |
drop_zero |
Drop unit-group combinations with zero weight. (Default |
Value
A data.table.
Examples
m <- matrix(c(10, 20, 30, 30, 20, 10), nrow = 3)
colnames(m) <- c("Black", "White")
long <- matrix_to_long(m, group = "race", unit = "school")
mutual_total(long, "race", "school", weight = "n")
[Package segregation version 1.1.0 Index]