Learn R Programming

biogram (version 1.6.3)

count_specified: Count specified n-grams

Description

Counts specified n-grams in the input sequence(s).

Usage

count_specified(seq, ngrams)

Arguments

seq

vector or matrix describing sequence(s).

ngrams

vector of n-grams.

Value

A simple_triplet_matrix where columns represent n-grams and rows sequences.

Details

count_specified counts only selected n-grams declared by user in the ngrams parameter. Declared n-grams must be written using the biogram notation.

See Also

Count all possible n-grams: count_ngrams.

Examples

Run this code
# NOT RUN {
seqs <- matrix(c(1, 2, 2, 1, 2, 1, 2, 1, 1, 2, 3, 4, 1, 2, 2, 4), nrow = 2)
count_specified(seqs, ngrams = c("1.1.1_0.0", "2.2.2_0.0", "1.1.2_0.0"))

seqs <- matrix(sample(1L:5, 200, replace = TRUE), nrow = 20)
count_specified(seqs, ngrams = c("2_4.2_0", "2_1.4_0", "3_1.3_0",
                                 "2_4.2_1", "2_1.4_1", "3_1.3_1",
                                 "2_4.2_2", "2_1.4_2", "3_1.3_2"))
# }

Run the code above in your browser using DataLab