#' A function to convert a slam::simple_triplet_matrix sparse matrix object to a dense matrix object.
#'
#' @param sparse_matrix A sparse matrix object generated by the slam library.
#' @return A dense matrix
#' @export
sparse_to_dense_matrix <- function(sparse_matrix){
nr <- sparse_matrix$nrow
nc <- sparse_matrix$ncol
## old line: y <- matrix(vector(typeof(x$v), nr * nc), nr, nc)
y <- matrix(0, nr, nc) ##
y[cbind(sparse_matrix$i, sparse_matrix$j)] <- sparse_matrix$v
dimnames(y) <- sparse_matrix$dimnames
return(y)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.