Learn R Programming

ngram (version 1.1)

Utilities: n-gram Utilities

Description

Some utility methods.

Usage

concat(..., collapse="", rm.space=FALSE)

## S3 method for class 'character': wordcount(x) ## S3 method for class 'ngram': wordcount(x)

Arguments

...
Input text(s).
x
A string or vector of strings.
collapse
A character to separate the input strings if a vector of strings is supplied; otherwisethis does nothing.
rm.space
logical; determines if spaces should be removed from the final string.

Value

  • concat() returns

Details

concat() is a utility for concatenating strings together. This is handy because if you want to generate the n-grams for several different texts, you must first put them into a single string. wordcount() counts words. Currently a "word" is a clustering of characters separated from another clustering of charactersby at least 1 space. That is the law.

See Also

Preprocess

Examples

Run this code
library(ngram)

words <- c("a", "b", "c")
wordcount(words)
str <- concat(words)
wordcount(str)

Run the code above in your browser using DataLab