Learn R Programming

ds4psy (version 0.7.0)

count_chars: Count the frequency of characters in a string of text x.

Description

count_chars provides frequency counts of the characters in a string of text x as a named numeric vector.

Usage

count_chars(x, case_sense = TRUE, rm_specials = TRUE, sort_freq = TRUE)

Arguments

x

A string of text (required).

case_sense

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

rm_specials

Boolean: Remove special characters? Default: rm_specials = TRUE.

sort_freq

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

Value

A named numeric vector.

Details

If rm_specials = TRUE (as per default), most special (or non-word) characters are removed and not counted. (Note that this currently works without using regular expressions.)

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

See Also

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

Other text objects and functions: Umlaut, capitalize(), caseflip(), cclass, count_chars_words(), count_words(), 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: 
x <- c("Hello world!", "This is a 1st sentence.", 
       "This is the 2nd sentence.", "THE END.")
count_chars(x)

# Options: 
count_chars(x, case_sense = FALSE)
count_chars(x, rm_specials = FALSE)
count_chars(x, sort_freq = FALSE)

# }

Run the code above in your browser using DataLab