Method to trim and adjust objects by applying thresholds, minimum frequencies
etc. It can be applied to context, features, context, partition and
partition_bundle objects.
trim(.Object, ...)
# S4 method for class 'TermDocumentMatrix'
trim(
.Object,
terms_to_drop,
docs_to_keep,
min_count,
min_doc_length,
verbose = TRUE,
...
)
# S4 method for class 'DocumentTermMatrix'
trim(
.Object,
terms_to_drop,
docs_to_keep,
min_count,
min_doc_length,
verbose = TRUE,
...
)
punctuationAn object of class character of length 13.
The object to be trimmed
further arguments
A character vector with terms to exclude from matrix
(terms used as stopwords).
A character vector with documents to keep.
A numeric value with a minimum value of total term
frequency across documents to exclude rare terms from matrix.
A numeric value with minimum total of the summed-up
occurrence of tokens in a document. Exclude documents below this value and
filter out short documents. Note that the min_doc_length filter is applied
before filtering for min_count and terms_to_keep, and that these filters
will reduce document lengths.
A logical value, whether to output progress messages.
use("RcppCWB", corpus = "REUTERS")
#> ✔ corpus loaded: REUTERS
dtm <- corpus("REUTERS") %>%
split(s_attribute = "id") %>%
as.DocumentTermMatrix(p_attribute = "word", verbose = FALSE)
#> ℹ s-attribute "id" has values: yes
#> ℹ get regions and get values
#> ✔ get regions and get values [14ms]
#>
#> ℹ instantiate objects (n = 20)
#> ✔ instantiate objects (n = 20) [10ms]
#>
#> ℹ assign names
#> ✔ assign names [9ms]
#>
trim(dtm, min_doc_length = 100)
#> ℹ minimum document length 100 - dropped 7 docs (keeping 13)
#> <<DocumentTermMatrix (documents: 13, terms: 1192)>>
#> Non-/sparse entries: 2031/13465
#> Sparsity : 87%
#> Maximal term length: 15
#> Weighting : term frequency (tf)