Learn R Programming

ds4psy (version 0.4.0)

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

Description

count_words counts the frequency of words in a string of text x.

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.

See Also

count_chars for counting the frequency of characters; plot_text for a corresponding plot function.

Other text objects and functions: Umlaut, capitalize(), caseflip(), cclass, count_chars(), l33t_rul35, metachar, read_ascii(), 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