Description Usage Arguments Value See Also Examples
Produces a frequency list of ngrams and returns a data frame. Users specify the number of words in the ngrams, the order of the frequency list as either alphabetical or by frequency, and whether the list be in ascending or descending order, among other options.
1 2 | ngram_freq(text, num_wd = 1, ignore_case = TRUE, order_by = "alpha",
descending = FALSE, min_freq = 1, word_char = NULL)
|
text |
The text with the ngrams whose frequencies are to be determined, as either a character vector or something coercible to it, such as a list of character vectors. |
num_wd |
Specifies the number of words in the ngrams, whether single words
( |
ignore_case |
Specifies whether the frequency list be
case-insensitive ( |
order_by |
Specifies whether the frequency list be ordered alphabetically
( |
descending |
Specifies whether the frequency list be ordered in
ascending order ( |
min_freq |
Specifies the minimum frequency that an ngram must have
in order to be included in the frequency list. With
|
word_char |
If |
A two-column local data frame, the first column with the ngrams and the second column with the frequencies.
For more info about local data frames, see https://cran.r-project.org/web/packages/dplyr/vignettes/data_frames.html).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | text <- c("First sentence here. Short, but sweet.")
text <- c(text, "Second one here, maybe?")
text <- c(text, "Third short paragraph here!")
text <- c(text, "Here too; with another thought.", "Here too.")
ngram_freq(text)
ngram_freq(text, ignore_case = FALSE)
ngram_freq(text, order_by = "freq", descending = TRUE)
ngram_freq(text, order_by = "freq", descending = TRUE, min_freq = 2)
# view difference (if any, given your locale)
ngram_freq("It's a hard-knock life, for us!")
ngram_freq("It's a hard-knock life, for us!", word_char = "[-'a-z]+")
# gets bigram frequencies
ngram_freq(text, num_wd = 2)
ngram_freq(text, num_wd = 2, order_by = "freq", descending = TRUE)
# gets trigram frequencies
ngram_freq(text, num_wd = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.