Learn R Programming

ds4psy (version 0.7.0)

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

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.

Value

A named numeric vector.

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).

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, count_chars_words(), count_chars(), l33t_rul35, map_text_chars(), map_text_coord(), map_text_regex(), metachar, read_ascii(), text_to_chars(), text_to_sentences(), text_to_words(), transl33t()

Examples

Run this code
# NOT RUN {
# 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

# }

Run the code above in your browser using DataLab