Switch the active context of a tidymatrix to operate on rows, columns, or the matrix itself. This determines which component will be affected by subsequent dplyr operations.
Examples
mat <- matrix(rnorm(12), nrow = 4, ncol = 3)
row_data <- data.frame(id = 1:4, group = c("A", "A", "B", "B"))
col_data <- data.frame(id = 1:3, type = c("x", "y", "z"))
tm <- tidymatrix(mat, row_data, col_data)
# Activate rows to filter/mutate row metadata
tm |> activate(rows)
#> # A tidymatrix: 4 x 3 matrix
#> # Active: rows
#> #
#> # Row data: 4 rows x 2 columns
#> # Column data: 3 rows x 2 columns
#> #
#> # Active data (rows):
#> id group
#> 1 1 A
#> 2 2 A
#> 3 3 B
#> 4 4 B
# Activate columns to work with column metadata
tm |> activate(columns)
#> # A tidymatrix: 4 x 3 matrix
#> # Active: columns
#> #
#> # Row data: 4 rows x 2 columns
#> # Column data: 3 rows x 2 columns
#> #
#> # Active data (columns):
#> id type
#> 1 1 x
#> 2 2 y
#> 3 3 z
# Activate matrix to work with the matrix directly
tm |> activate(matrix)
#> # A tidymatrix: 4 x 3 matrix
#> # Active: matrix
#> #
#> # Row data: 4 rows x 2 columns
#> # Column data: 3 rows x 2 columns
#> #
#> # Matrix preview:
#> [,1] [,2] [,3]
#> [1,] -1.400043517 0.6215527 -0.2441996
#> [2,] 0.255317055 1.1484116 -0.2827054
#> [3,] -2.437263611 -1.8218177 -0.5536994
#> [4,] -0.005571287 -0.2473253 0.6289820