© Thomas Mailund 2017

Thomas Mailund, Functional Programming in R, 10.1007/978-1-4842-2746-6_4

4. Higher-Order Functions

Thomas Mailund

(1)Aarhus N, Denmark

The term higher-order functions refers to functions that either take functions as arguments or return functions. The functions we used to create closures in Chapter 3 are thus higher-order functions. Higher-order functions are frequently used in R instead of looping control structures, and we will cover how you can do this in general in Chapter 6. A quick example is provided in this chapter before moving on to more interesting things we can do with functions working on functions.

The function sapply (it stands for simplifying apply) lets you call a function for all elements in a list or vector. ...

Get Functional Programming in R: Advanced Statistical Programming for Data Science, Analysis and Finance now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.