Filter: Filter

View source: R/wfm.R

Filter.all_wordsR Documentation

Filter

Description

Filter.all_words - Filter words from a all_words that meet max/min word length criteria.

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.wfm - Filter words from a wfm that meet max/min word length criteria.

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

Filter.fwl - Filter words from a fwl that meet max/min word length criteria.

Filter.fswl - Filter words from a fswl that meet max/min word length criteria.

Filter.rfswl - Filter words from a rfswl that meet max/min word length criteria.

Usage

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

## 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 'wfm'
Filter(x, min = 1, max = Inf, count.apostrophe = TRUE, stopwords = NULL, ...)

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

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

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

## S3 method for class 'rfswl'
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.

Details

all_words Method for Filter

TermDocumentMatrix Method for Filter

DocumentTermMatrix Method for Filter

character Method for Filter

fwl Method for Filter

fswl Method for Filter

rfswl Method for Filter

Value

Filter.all_words - Returns a matrix of the class "all_words".

Filter.TermDocumentMatrix - Returns a matrix of the class "TermDocumentMatrix".

Filter.DocumentTermMatrix - Returns a matrix of the class "DocumentTermMatrix".

Filter - Returns a matrix of the class "wfm".

Filter.character - Returns a vector of the class "character".

Filter.wfm - Returns a matrix of the class "wfm".

Filter.fwl - Returns a matrix of the class "fwl".

Filter.fswl - Returns a matrix of the class "fswl".

Filter.rfswl - Returns a matrix of the class "rfswl".

Note

The name and idea behind this function is inspired by the dplyr package's filter function and has a similar meaning in that you are grabbing rows (or elements) meeting a particular criteria.

Examples

## Not run: 
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

## Filter `all_words`
head(all_words(raj$dialogue))
Filter(head(all_words(raj$dialogue)), min = 3)

## End(Not run)

qdap documentation built on May 31, 2023, 5:20 p.m.