count_words: Count the frequency of words in a string of text

View source: R/text_fun.R

count_wordsR Documentation

Count the frequency of words in a string of text

Description

count_words provides frequency counts of the words in a string of text x as a named numeric vector.

Usage

count_words(x, case_sense = TRUE, sort_freq = TRUE)

Arguments

x

A string of text (required).

case_sense

Boolean: Distinguish lower- vs. uppercase characters? Default: case_sense = TRUE.

sort_freq

Boolean: Sort output by word frequency? Default: sort_freq = TRUE.

Details

Special (or non-word) characters are removed and not counted.

The quantification is case-sensitive and the resulting vector is sorted by name (alphabetically) or by frequency (per default).

Value

A named numeric vector.

See Also

count_chars for counting the frequency of characters; count_chars_words for counting both characters and words; plot_chars for a character plotting function.

Other text objects and functions: Umlaut, capitalize(), caseflip(), cclass, chars_to_text(), collapse_chars(), count_chars(), count_chars_words(), invert_rules(), l33t_rul35, map_text_chars(), map_text_coord(), map_text_regex(), metachar, read_ascii(), text_to_chars(), text_to_sentences(), text_to_words(), transl33t(), words_to_text()

Examples

# Default: 
s3 <- c("A first sentence.", "The second sentence.", 
        "A third --- and also THE FINAL --- SENTENCE.")
count_words(s3)  # case-sensitive, sorts by frequency 

# Options: 
count_words(s3, case_sense = FALSE)  # case insensitive
count_words(s3, sort_freq = FALSE)   # sorts alphabetically


hneth/ds4psy documentation built on Feb. 29, 2024, 8:49 a.m.