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)
Run the code above in your browser using DataLab