Tokenises text (splitting on whitespace, lower-casing, and stripping
punctuation), removes stop words, and counts term frequency. Ships a
small built-in English stop-word list so this works with zero optional
packages; pass stop_words = character(0) to disable filtering, or a
custom vector to override it.
Arguments
- text
Character vector of responses (raw or already cleaned by
clean_text_responses()).- stop_words
Character vector of words to exclude, or
NULLto use the built-in English list, orcharacter(0)for no filtering.- top_n
Integer. Maximum number of terms to return, most frequent first. Default
30.
Examples
demo <- sframe_demo_data()
cleaned <- clean_text_responses(demo$responses, "comments")
head(term_frequency(cleaned, top_n = 10))
#> term n pct
#> 1 details 35 13.0
#> 2 like 35 13.0
#> 3 sustainability 35 13.0
#> 4 clear 31 11.5
#> 5 content 31 11.5
#> 6 online 31 11.5