A tidymatrix combines a matrix with row and column metadata, enabling tidyverse-style manipulation. The object stores three components: the matrix data, row annotations, and column annotations.
Arguments
- matrix
A numeric matrix
- row_data
A data.frame with row metadata. Must have same number of rows as the matrix. If NULL, a data.frame with row indices is created.
- col_data
A data.frame with column metadata. Must have same number of rows as the matrix has columns. If NULL, a data.frame with column indices is created.
Examples
# Create a simple tidymatrix
mat <- matrix(rnorm(12), nrow = 4, ncol = 3)
row_data <- data.frame(
person_id = 1:4,
age = c(25, 30, 35, 40),
gender = c("M", "F", "F", "M")
)
col_data <- data.frame(
question_id = 1:3,
type = c("numeric", "categorical", "numeric")
)
tm <- tidymatrix(mat, row_data, col_data)