Skip to contents

Generates n-grams from queries

Usage

kwr_ngrams(
  x,
  max_words = 4,
  min_words = 1,
  min_n = 1,
  min_volume = 0,
  remove_nested = TRUE
)

Arguments

x

A kwresearch object, which queries will be n-grams calculated from, or a data frame of queries and volume.

max_words

Maximum number of words in n-grams.

min_words

Minimum number of words in n-grams.

min_n

Minimum number of queries. Only the n-grams with at least this number of queries will be included.

min_volume

Minimum search volume per n-gram. Only the n-grams with at least this volume will be included.

remove_nested

If TRUE, n-grams fully contained in another n-gram (number of queries must be the same) are filtered out from the result. May be slower.

Value

A tibble of n-grams with a basic stats (number of queries and sum of search volumes). The n-grams are ordered descendingly by number of queries and search volume. Use dplyr::arrange to change order. If stop words are set with the kwr_use_stopwords, they are removed from unigrams.

Examples

queries <- data.frame(
  query = c("seo", "keyword research", "seo research"),
  volume = c(1000, 500, 100)
)
kwr <- kwresearch(queries)
kwr_ngrams(kwr)
#> # A tibble: 4 × 3
#>   token                n volume
#>   <chr>            <int>  <dbl>
#> 1 seo                  2   1100
#> 2 research             2    600
#> 3 keyword research     1    500
#> 4 seo research         1    100