Chapter 3 of my book “Modeling data with functional programming in R” is available for download. This chapter describes map-vectorization and how it’s used in R. I make a distinction between different types of vectorization since
f(x) = x^2 + 2*y - 5 is vectorized differently from
sum(x). I call the first form map-vectorization, after the higher-order function map. In R, we call this
apply, though conceptually they represent the same operation.
This chapter uses the
ebola.sitrep package I wrote as the basis for examples. The package downloads and parses PDF situation reports from the Health Ministries of Liberia and Sierra Leone. The parsing process is filled with examples of map operations, and I discuss numerous cases in the chapter. I also delve into some of the properties of map and how these can be used to reason about your code to ultimately implement your ideas succinctly.
Thanks for reading, and all germane comments are welcome.