How often should you expect to have a truly record breaking year? Suppose you have 100 years of weather data indicating how much precipitation fell in each year. How many records to you expect to be set for wettest or driest years on record? For example, according to NOAA, St. Louis' official driest year had just 20.7 inches of precipitation in 1953, and our wettest year had 61.2 inches in 2015. On average, we get about 43.4 inches of precipitation in a year.
In this class we will simulate weather data and compute how many record highs and lows are seen. To do this, we build upon our exercise from last time, the peak-finding function.
Given a vector, we have discussed the basic algorithm for fiding the maximum, by keep track of the maximum thus far while iterating through the vector.
Question: how many different elements qualify as being the maximum thus far during that process?
Goal: Develop a function peaks(v) that returns the number of
elements that have value surpassing all previous elements in the vector.
For example,
Goal: Rewrite the function so that it can provide a second return
value, which is a vector of indices achieving those peaks (akin to the
second return value of the built-in max function). Thus