countWords: Count words

View source: R/countWords.R

countWordsR Documentation

Count words

Description

Function counts the words in each document

Usage

countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

## S3 method for class 'Corpus'
countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

## S3 method for class 'character'
countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

## S3 method for class 'data.frame'
countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

## S3 method for class 'TermDocumentMatrix'
countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

## S3 method for class 'DocumentTermMatrix'
countWords(
  x,
  aggregate = NULL,
  removeStopwords = TRUE,
  language = "english",
  ...
)

Arguments

x

A vector of characters, a data.frame, an object of type Corpus, TermDocumentMatrix or DocumentTermMatrix

aggregate

A factor variable by which documents can be grouped. This helpful when joining e.g. news from the same day or move reviews by the same author

removeStopwords

Flag indicating whether to remove stopwords or not (default: yes)

language

Language used for preprocessing operations (default: English)

...

Additional parameters passed to function for e.g. preprocessing

Value

Result is a matrix with word counts for each document across

Examples

documents <- c("This is a test", "an one more")

# count words (without stopwords)
countWords(documents)

# count all words (including stopwords)
countWords(documents, removeStopwords=FALSE)

SentimentAnalysis documentation built on Aug. 24, 2023, 1:07 a.m.