R/transform_count_matrix_to_corpus.R

Defines functions transform_count_matrix_to_corpus

Documented in transform_count_matrix_to_corpus

#' Transform a count matrix into a corpus data.frame
#'
#' @import magrittr
#' @importFrom magrittr %>%
#' @export
transform_count_matrix_to_corpus <-  function(data){
  if (is.null(colnames(data))) {
    warning(
      paste0("The column names (the features) were not provided.
             Replacing them with 'w1'...'w",ncol(data),"'\n")
    )
    colnames(data) <- paste0("w", 1:ncol(data))
  }
  purrr::map_dfr(
    .x = 1:nrow(data),
    .f = function(i) {
      rep(colnames(data), data[i,]) %>%
        sample() %>% # for fun
        stringr::str_c(., collapse = " ") %>%
        tibble::as_tibble()
    }
  )
}
lasy/hLDA documentation built on June 15, 2024, midnight