powered by
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.
matrix_to_long( matrix, group = "group", unit = "unit", weight = "n", drop_zero = TRUE )
A data.table.
A matrix, where the rows represent the units, and the column represent the groups.
Variable name for group. (Default group)
group
Variable name for unit. (Default unit)
unit
Variable name for frequency weight. (Default weight)
weight
Drop unit-group combinations with zero weight. (Default TRUE)
TRUE
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")
Run the code above in your browser using DataLab