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.
Arguments
- matrix
A matrix, where the rows represent the units, and the column represent the groups.
- group
Variable name for group. (Default
group
)- unit
Variable name for unit. (Default
unit
)- weight
Variable name for frequency weight. (Default
weight
)- drop_zero
Drop unit-group combinations with zero weight. (Default
TRUE
)
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")
#> stat est
#> 1: M 0.08720802
#> 2: H 0.12581458