Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ngrams

Compute N-Grams


Description

Compute the n-grams (contiguous sub-sequences of length n) of a given sequence.

Arguments

x

a sequence (vector).

n

a positive integer giving the length of contiguous sub-sequences to be computed.

Value

a list with the computed sub-sequences.

Examples

s <- "The quick brown fox jumps over the lazy dog"
## Split into words:
w <- strsplit(s, " ", fixed = TRUE)[[1L]]
## Word tri-grams:
ngrams(w, 3L)
## Word tri-grams pasted together:
vapply(ngrams(w, 3L), paste, "", collapse = " ")

NLP

Natural Language Processing Infrastructure

v0.2-1
GPL-3
Authors
Kurt Hornik [aut, cre] (<https://orcid.org/0000-0003-4198-9911>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.