This function takes a data frame containing a label column and adds bi-, tri-, and n-grams. It uses the tidytext library to allow dynamic specification of n and returns the same data frame with added column ngrams_n where n is defined by the input.

add_ngram(df, inner_col, n = 2, exclude_self = FALSE)

Arguments

df

An tibble

inner_col

The column name of the label column as a string

n

depth of the n-gram (default: 2, i.e. add bigrams)

exclude_self

exclude self-transitions? (default: FALSE)

Value

The input data frame with column ngrams_n added