Learn R Programming

SentimentAnalysis (version 1.3-4)

countWords: Count words

Description

Function counts the words in each document

Usage

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

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

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

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

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

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

Value

Result is a matrix with word counts for each document across

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

Examples

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

# count words (without stopwords)
countWords(documents)

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

Run the code above in your browser using DataLab