Exercise

Multiple iterators in word frequency

This exercise is a modification of the previous one. Now assume you want to vary the minimum word length across the letters of the alphabet. Specifically, your job is to modify the code so that the maximum frequency for the first half of the alphabet is obtained for words that are two and more characters long, while the frequency corresponding to the second half of the alphabet is derived from words that are six and more characters long. Note that we are using an alphabet of 26 characters.

Your namespace has all the objects from the previous exercise, plus the foreach package is loaded.

Instructions

100 XP
  • Construct a foreach-%do%loop as follows:
    • As before, function max_frequency() is called on each letter of the alphabet using the iterator let.
    • Use the iterator n to define multiple values of the min_length argument. It is equal to 2 in the first 13 iterations and equal to 6 in the last 13 iterations. Use c() and rep() to construct n so that it has the same length as let.
    • Results are combined into a vector.
  • Show results as barplot.