Word frequency in R
Word frequencies with table, R's one-line counter.
count_words <- function(text) {
words <- tolower(unlist(strsplit(text, "\\s+")))
words <- words[words != ""]
sort(table(words), decreasing = TRUE)
}
Keywords and builtins used here
functionsortstrsplittabletolowerunlist
The run, in numbers
- Lines
- 5
- Characters to type
- 148
- Tokens
- 43
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 27 seconds.
Step 3 of 3 in Text & dates, step 19 of 20 in Language basics.