Extract n-grams from sequence

Share:

Description

Extracts vector of n-grams present in sequence(s).

Usage

1
seq2ngrams(seq, n, u, d = 0, pos = FALSE)

Arguments

seq

a vector or matrix describing sequence(s).

n

integer size of n-gram.

u

integer, numeric or character vector of all possible unigrams.

d

integer vector of distances between elements of n-gram (0 means consecutive elements). See Details.

pos

logical, if TRUE position-specific n_grams are counted.

Details

A format of d vector is discussed in Details of count_ngrams.

Value

A character matrix of n-grams, where every row corresponds to a different sequence.

Examples

1
2
3
# trigrams from multiple sequences
seqs <- matrix(sample(1L:4, 600, replace = TRUE), ncol = 50)
seq2ngrams(seqs, 3, 1L:4)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.