Learn R Programming

ngram (version 1.1)

Process: ngram

Description

This routine processes a string into an ngram class object.

Usage

## S3 method for class 'character':
ngram(x, n=2)

Arguments

x
The input text.
n
The 'n' as in 'n-gram'.

Details

The ngram() function is the main workhorse of this package. It takes an input string and converts it into the internal n-gram representation. On evaluation, a copy of the input string is produced and stored as an external pointer. This is necessary because the internal list representation just points to the first char of each word in the input string. So if you (or R's gc) deletes the input string, basically all hell breaks loose.

See Also

ngram-class

Examples

Run this code
library(ngram)

str <- "A B A C A B B"
ng <- ngram(str, n=2)
ng

Run the code above in your browser using DataLab