Learn R Programming

qdap (version 1.3.2)

Filter.TermDocumentMatrix: Filter

Description

Filter.TermDocumentMatrix - Filter words from a TermDocumentMatrix vector that meet max/min word length criteria. Filter.DocumentTermMatrix - Filter words from a DocumentTermMatrix that meet max/min word length criteria. Filter - Filter words from various objects that meet max/min word length criteria. Filter.character - Filter words from a character vector that meet max/min word length criteria.

Usage

## S3 method for class 'TermDocumentMatrix':
Filter(x, min = 1, max = Inf,
  count.apostrophe = TRUE, stopwords = NULL, ignore.case = TRUE, ...)

## S3 method for class 'DocumentTermMatrix':
Filter(x, min = 1, max = Inf,
  count.apostrophe = TRUE, stopwords = NULL, ignore.case = TRUE, ...)

Filter(x, min = 1, max = Inf, count.apostrophe = TRUE, stopwords = NULL,
  ignore.case = TRUE, ...)

## S3 method for class 'character':
Filter(x, min = 1, max = Inf, count.apostrophe = TRUE,
  stopwords = NULL, ignore.case = TRUE, ...)

Arguments

x
A filterable object (e.g., wfm, character).
min
Minimum word length.
max
Maximum word length.
count.apostrophe
logical. If TRUE apostrophes are counted as characters.
stopwords
A vector of stop words to remove.
ignore.case
logical. If TRUE stopwords will be removed regardless of case (ignored if used on a wfm).
...
Other arguments passed to specific Filter methods.

Value

  • Filter.TermDocumentMatrix - Returns a matrix of the class "TermDocumentMatrix". Filter.DocumentTermMatrix - Returns a matrix of the class "DocumentTermMatrix". Filter.character - Returns a vector of the class "character". Filter.wfm - Returns a matrix of the class "wfm".

Details

TermDocumentMatrix Method for Filter DocumentTermMatrix Method for Filter character Method for Filter

Examples

Run this code
Filter(with(DATA, wfm(state, list(sex, adult))), 5)
with(DATA, wfm(state, list(sex, adult)))

## Filter particular words based on max/min values in wfm
v <- with(DATA, wfm(state, list(sex, adult)))
Filter(v, 5)
Filter(v, 5, count.apostrophe = FALSE)
Filter(v, 5, 7)
Filter(v, 4, 4)
Filter(v, 3, 4)
Filter(v, 3, 4, stopwords = Top25Words)

## Filter works on character strings too...
x <- c("Raptors don't like robots!",  "I'd pay $500.00 to rid them.")
Filter(x, 3)
Filter(x, 4)
Filter(x, 4, count.apostrophe = FALSE)
Filter(x, 4, count.apostrophe = FALSE, stopwords="raptors")
Filter(x, 4, stopwords="raptors")
Filter(x, 4, stopwords="raptors", ignore.case = FALSE)

DATA[, "state"] <- Filter(DATA[, "state"], 4)
DATA <- qdap::DATA

Run the code above in your browser using DataLab