#' A function to convert a quanteda dfm object to a slam::simple_triplet_matrix.
#'
#' @param quanteda_dfm A dfm object generated by the quanteda::dfm() function.
#' @export
convert_quanteda_to_slam <- function(quanteda_dfm){
# convert to a topicmodels object, which is just some window dressing on a
# slam::simple_triplet_matrix
dtm <- quanteda::convert(quanteda_dfm, to = "topicmodels")
# create a blank object to populate
temp <- slam::simple_triplet_matrix(i = 1,
j = 1,
v = 1)
# slot the information into the blank simple_triplet_matrix
temp$i <- dtm$i
temp$j <- dtm$j
temp$v <- dtm$v
temp$nrow <- dtm$nrow
temp$ncol <- dtm$ncol
temp$dimnames <- dtm$dimnames
return(temp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.