table_to_matrix | R Documentation |
Switch table to matrix
table_to_matrix(
table,
row_names = NULL,
col_names = NULL,
threshold = 0,
return_sparse = FALSE
)
table |
A table with three columns: |
row_names |
Character vector of row names to filter by. |
col_names |
Character vector of column names to filter by. |
threshold |
The threshold for filtering values based on absolute values.
Defaults to |
return_sparse |
Whether to return a sparse matrix. Defaults to |
A matrix.
table <- data.frame(
row = c("r1", "r2", "r3", "r4", "r5", "r6"),
col = c("c4", "c5", "c6", "c1", "c2", "c3"),
value = c(0.6, -0.5, -0.4, 0.3, 0.2, 0.1)
)
matrix <- table_to_matrix(table)
table_new <- matrix_to_table(matrix)
identical(table, table_new)
table_to_matrix(table, threshold = 0.3)
table_to_matrix(
table,
row_names = c("r1", "r2"),
col_names = c("c4", "c5")
)
sparse_matrix <- simulate_sparse_matrix(10, 10)
table_sparse <- matrix_to_table(
sparse_matrix,
keep_zero = TRUE
)
sparse_matrix_new <- table_to_matrix(
table_sparse,
return_sparse = TRUE
)
identical(sparse_matrix, sparse_matrix_new)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.