Exercise

Word frequency with foreach

Recall the first chapter where you found the most frequent words from the janeaustenr package that are of certain minimum length. It looked like this:

result <- lapply(letters, max_frequency,
            words = words, min_length = 5) %>% unlist

In this exercise, you will implement the foreach construct to solve the same problem.

The janeaustenr package, a vector of all words from the included books, words, and a function max_frequency() for finding the results based on a given starting letter are all available in your workspace.

Instructions

100 XP
  • Load the foreach package.
  • Construct a foreach-%do% loop so that it is equivalent to the lapply() solution from above, including combining results into a vector using the .combine operator.
    • The iterator let iterates over letters, each of which is passed to the max_frequency() function, along with arguments words and min_length specified in the context section.
  • Show results as barplot.