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

View source: R/text_fun.R

count_charsR Documentation

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.

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

Value

A named numeric vector.

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, chars_to_text(), collapse_chars(), count_chars_words(), count_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: 
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)


ds4psy documentation built on Sept. 15, 2023, 9:08 a.m.