Total count of each vocabulary term over the documents of an
STM input (documents is a list of 2-row matrices: term indices,
counts), optionally within the groups defined by covariates, e.g. the
most frequent terms by decade or by document type.
Arguments
- stm_data
A list with
documentsandvocab(e.g. the output oftokens_to_stm(),stm::prepDocuments()orquanteda::convert(to = "stm")).- by
Optional character vector of columns of
stm_data$meta(one row per document, as built bytokens_to_stm()) to count by.NULLcounts over the whole corpus.- ...
Not used: an argument renamed in the development version of mintR gives an error naming its replacement.
Value
A data.table with the by columns (if any), term and count,
by decreasing count. Terms that never occur (in the group) are absent.
Examples
stm_data <- list(
documents = list(matrix(c(1L, 2L, 2L, 1L), 2), matrix(c(2L, 3L), 2)),
vocab = c("wage", "labour"),
meta = data.frame(type = c("a", "b"))
)
term_counts(stm_data)
#> term count
#> <char> <num>
#> 1: labour 4
#> 2: wage 2
term_counts(stm_data, by = "type")
#> type term count
#> <char> <char> <num>
#> 1: b labour 3
#> 2: a wage 2
#> 3: a labour 1
