13. Iterating with purrr
R
has numerous ways to iterate over the elements of a list
(or vector
), and Hadley Wickham aimed to improve on and standardize that experience with the purrr package. R
has its roots in functional programming, and purrr is designed to utilize that computing paradigm. For our purposes, functional programming is when a function depends only on its input arguments. This enables us to iterate over a list
and apply a function to each element independently. This is mainly aimed at operating on list
s, though it can also be used to apply non-vectorized functions to vector
s.
The name purrr has many meanings. It is primarily meant to convey that this package enforces pure programming. It is also a pun on a cat purring and has five ...
Get R for Everyone: Advanced Analytics and Graphics, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.